2012-03-15 13 views
12

Come includere un apice in annotazione ggplot? Voglio visualizzare Rsuperscript2 = someValue Ho provato ad utilizzare parse = TRUE all'interno annotare .. Mi ha dato = Rsuperscript2, someValue inveceannotazione ggplot2 con apici

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) 

risposta

28

è il problema con apici o con il segno di uguale? Passando a == nell'espressione, con parse=TRUE funziona per me. Non avendo il tuo dData, ecco un esempio fittizio.

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