I am new here but I read in this forum for a longer time and gained a lot of knowledge in R. However, currently I am struggling in changing the text strip in facet plots in ggplot2. I tried to use the text strips to Label the y-axis by flipping them to the right side. This actually works fine, also a line break was no problem. What I am not able to create are Special characters. I tried both variants described here: http://www.cookbook-r.com/Graphs/Facets_(ggplot2)/ under Header: "Modifying facet label text"
Other methods of labelling as described here http://docs.ggplot2.org/current/labellers.html I can unfortunatly not transfer to my code.
Here a part of my code as example: (In both cases, '-1' should be superscript)
###Try to use labels
labels<-c(Cmic="Cmic \n [g kg-1]", Corg="Corg \n [g kg-1]")
###Instead: Try to Change levels
levels(Bodenbiologie$Größe)[levels(Bodenbiologie$Größe)=="Cmic"]<-"Cmic~\n~ [g kg-1]"
levels(Bodenbiologie$Größe)[levels(Bodenbiologie$Größe)=="Corg"]<-"Corg~\n~[g kg-1]"
It would be really nice, if somebody could help my!
Thanks in advance!
Here now a reproducible dummy example of the Problem:
Variante <- c("D","D","D","C","C","C")
Bezeichnung <- c("Treat","Treat","Treat","Con","con","con")
Größe <- c("A","B","C","A","B","C")
mean <- c(5,10,15,7,14,21)
standdev <- c(2.5,5,7.5,3.5,7,10.5)
Problem<-data.frame(Variante, Bezeichnung, Größe, mean, standdev)
library(ggplot2)
attach(Problem)
names(Problem)
labels<-c(A="Test \n (Test^1)", B="SOM \n (g kg^{-1} d.m.)", C=" Check \n (kg[2])")
Abb1<-ggplot(Problem, aes(x=Bezeichnung, y=mean, fill=(Größe)))+
geom_boxplot(stat="boxplot", position = "dodge", width=0.5)+
labs(title="", x= "", y="")
Abb1
Abb2<-Abb1 + facet_grid(Größe~., scale="free_y", switch="both",labeller=labeller(Größe=labels))+
stat_boxplot(geom ='errorbar', width=0.5) +
geom_boxplot(stat="boxplot", position = "dodge", width=0.75)
Abb2
Thanks in advance!