r - ggplot2 facet_wrap 与数学表达式

标签 r math ggplot2 facet-wrap

使用facet_wrap(),我想用数学表达式标记每个单独的图:

library(ggplot2)

x       <- rnorm(100, 50, 10)
y       <- rnorm(100, 50, 10)
grp     <- rep(c("a", "b", "c", "d"), each=25)
test.df <- data.frame(grp, x, y)
mean.df <- aggregate(test.df[c("x", "y")], test.df["grp"], mean)

p <- ggplot(test.df) +
     geom_point(aes(x=x, y=y, col=grp)) + 
     facet_wrap(~ grp) +
     geom_text(data=mean.df, aes(x=x, y=y, label=paste("xbar=", round(x,1))))
p

我想要\bar(x) 而不是 xbar。我尝试了表达式(),但我得到:“无法将类“表达式”强制到 data.frame”。

最佳答案

使用

geom_text(data = mean.df, parse = TRUE,
          aes(x = x, y = y, label = paste("bar(x) ==", round(x, 1))))

帮助。

enter image description here

关于r - ggplot2 facet_wrap 与数学表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35044906/

相关文章:

r - ggplot2如何在 map 边界(例如美国州)内保持抖动的位置?

r - 如何解决ubuntu 16.04中的 "ssl certificate problem: unable to get local issuer certificate"

r - 拟合序数逻辑混合效应模型

java - 两个(小)数相乘给出负数解,而不是溢出……那为什么呢?

javascript - 使用随机数学来选择和放置图像

r - R:使用莱迪思和ggplot2的利弊是什么?

r - 用R计算黄土拟合曲线的最小/最大斜率?

r - R 中的结构方程建模——有什么好书或教程吗?

r - 在 R 中选择 data.table 键

javascript - 如何在 JavaScript 中执行整数除法并分别获取余数?