【问题标题】:ggplot2 facet_wrap with mathematical expression带有数学表达式的ggplot2 facet_wrap
【发布时间】:2016-01-27 18:10:01
【问题描述】:

使用 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”。

【问题讨论】:

    标签: r math ggplot2 facet-wrap


    【解决方案1】:

    使用

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

    帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 2017-05-24
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      相关资源
      最近更新 更多