2012-03-15 79 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