带有上标的ggplot2批注 [英] ggplot2 annotation with superscripts

查看:153
本文介绍了带有上标的ggplot2批注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I include a superscript in ggplot annotation? I want to display Rsuperscript2 = somevalue I tried using parse=TRUE inside annotate.. It gave me = Rsuperscript2 , somevalue instead

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)

推荐答案

上标或等号是问题吗?用parse=TRUE切换到表达式中的==对我有用.没有您的dData,这是一个虚拟示例.

Is the problem with superscripts or with the equals sign? Switching to == in the expression, with parse=TRUE works for me. Not having your dData, here is a dummy example.

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

这篇关于带有上标的ggplot2批注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆