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)
To add superscript as a title add bquote function with value inside ggtitle(). Parameter : like xlab and ylab functions, we can give the title for plot directly using this function. Here we will bquote() function for writing Superscript value ( Number VS Number2 ) as a title of plot.
To indicate a subscript, use the underscore _ character. To indicate a superscript, use a single caret character ^ . Note: this can be confusing, because the R Markdown language delimits superscripts with two carets. In LaTeX equations, a single caret indicates the superscript.
If you want to annotate your plot or figure with labels, there are two basic options: text() will allow you to add labels to the plot region, and mtext() will allow you to add labels to the margins. For the plot region, to add labels you need to specify the coordinates and the label.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With