2012-03-15 102 views
12

如何在ggplot注释中包含上标?我想显示Rsuperscript2 = someValue中 我尝试使用解析= TRUE内注释。它给了我= Rsuperscript2,someValue中,而不是带上标的ggplot2注释

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) 

回答

28

是与标或等号的问题?在表达式中切换为==,其中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) 

enter image description here