我需要在多面ggplots中用不同的标签注释不同的方面。是的,我尝试根据此类似问题的响应创建一个附加的数据框来保存批注。 Annotating text on individual facet in ggplot2
挑战在于,由于注释包含下标;我必须使用函数“表达式”来构造它们,以便随后可以使用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)
)
此代码给出了错误声明:
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ""expression"" to a data.frame
请提供任何帮助。
编辑:这是我的ggplot2代码。
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)