I need to annotate different facet with different labels in a faceted ggplots. Yes, I try creating an additional data frame to hold the annotations as per a response to this similar question. Annotating text on individual facet in ggplot2
The challenge is that since the annotation includes subscripts; I have had to use function 'expression' to construct them so I can then use geom_text.
ModelDisplay = data.frame(
label = c(expression(model:0.0034+0.0011*Sph[4216]*(h)), expression(model:0.0034+0.0011*Sph[4216]*(h)), expression(model:0.0034+0.0011*Sph[4216]*(h)),expression(model:0.0034+0.0011*Sph[4216]*(h))),
dir.hor = c(45, 90, 135, 180)
)
This code gave the error statement:
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ""expression"" to a data.frame
Please any help would be appreciated.
Edit: Here is my ggplot2 code.
ggplot(data = allazimvariogram_EmpandMod_lagbased, aes(x = dist, y = gamma))+
labs(x = "Lag Distance, m", y = "Porosity Empirical Variogram")+
geom_point(color = "blue") +
coord_cartesian(xlim = c(0, 8000), ylim = c(0, 0.008))+
scale_x_continuous(breaks = seq(0, 8000, by = 2000))+
scale_y_continuous(breaks = seq(0, 0.008, by = 0.001))+
geom_smooth(aes(x=dist, y=Modgamma), se = FALSE, colour = "red")+
geom_text(data = ModelDisplay, mapping = aes(x = -Inf, y = -Inf, label = label),hjust = -0.1,vjust = -1, parse = T)+
facet_wrap(~ dir.hor, nrow = 2)