I am trying to get facet labels with a new line and exponents and I can get one or the other but not both. Code for the two possibilities is below
The first attempt correctly gives the exponent in the top facet label but I would like the volumetric water content to be on two lines.
The second attempt correctly puts the volumetric water content on two lines but the exponent in the top facet label is not correct, and the % in the second one is not correct.
n2 <- NULL
n2$Animal <- c(rep("cattle",36),rep("sheep",36))
n2$LowHill <- c(rep("low",6),rep("med",6),rep("steep",6),rep("low",6),rep("med",6),rep("steep",6),
rep("low",6),rep("med",6),rep("steep",6),rep("low",6),rep("med",6),rep("steep",6))
n2$Variable <- c(rep("BD",12),rep("pH",12),rep("OP",12),rep("OC",12),rep("TN",12),rep("SW",12))
n2$Vars <- factor(n2$Variable, labels= c( 'bulk~density~(Mg/m^3)',"soil~organic~C~('%')", "Olsen~P~( \u03BCg/ml)","soil~pH", 'volumetric~water~content~\n~(v/v~average~of~first~30~days)',"soil~total~N"))
n2$var <- rnorm(72,1,0.1)
n2 <- as.data.frame(n2)
pall <- ggplot(n2, aes(x=LowHill, y=var)) + geom_jitter(width=0.2,height=0) pall <- pall + geom_boxplot() pall <- pall + theme_bw() + ylab(" ") pall <- pall + facet_grid(Vars~Animal, scales="free_y",labeller=label_parsed ) pall <- pall + theme(strip.text.y = element_text(angle=0)) pall
#####################################
n2 <- NULL
n2$Animal <- c(rep("cattle",36),rep("sheep",36))
n2$LowHill <- c(rep("low",6),rep("med",6),rep("steep",6),rep("low",6),rep("med",6),rep("steep",6),
rep("low",6),rep("med",6),rep("steep",6),rep("low",6),rep("med",6),rep("steep",6))
n2$Variable <- c(rep("BD",12),rep("pH",12),rep("OP",12),rep("OC",12),rep("TN",12),rep("SW",12))
n2$Vars <- factor(n2$Variable, labels= c( 'bulk density (Mg/m^3)',"soil organic C ('%')", "Olsen P ( \u03BCg/ml)","soil pH", 'volumetric water content\n (v/v average of first 30 days)',"soil total N"))
n2$var <- rnorm(72,1,0.1)
n2 <- as.data.frame(n2)
pall <- ggplot(n2, aes(x=LowHill, y=var)) + geom_jitter(width=0.2,height=0) pall <- pall + geom_boxplot() pall <- pall + theme_bw() + ylab(" ") pall <- pall + facet_grid(Vars~Animal, scales="free_y",labeller=labeller(type=label_parsed )) pall <- pall + theme(strip.text.y = element_text(angle=0)) pall