【问题标题】:ggplot2 annotation with superscripts带有上标的ggplot2注释
【发布时间】:2012-03-15 15:46:25
【问题描述】:

如何在 ggplot 注释中包含上标?我想显示 Rsuperscript2 = somevalue 我尝试在注释中使用 parse=TRUE 。它给了我 = Rsuperscript2 ,而不是一些值

lm1 <- lm(dData$RF ~ dData$Exp -1)
lb1 <- paste("R^2 = ", round(summary(lm1)$r.squared,4))
p1 <- ggplot(dData, aes(x=dData$Exp, y=dData$RF)) +
  scale_x_continuous("Experimental") + 
  scale_y_continuous("Predicted") + 
  geom_point() + geom_smooth(method="lm") + 
  annotate("text", x=max(dData$Exp), y=min(dData$RF)+1, label=lb1, 
           hjust=1, size=3, vjust=1)

【问题讨论】:

  • 不是可重现的例子

标签: r ggplot2


【解决方案1】:

是上标的问题还是等号的问题?在表达式中切换到 ==,parse=TRUE 对我有用。没有你的dData,这是一个虚拟的例子。

lb1 <- paste("R^2 == ", round(runif(1),4))
qplot(1:10, 1:10) + 
  annotate("text", x=2, y=8, label=lb1, parse=TRUE)

【讨论】:

    猜你喜欢
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多