"Squared" superscript in ggplot2 yaxis label in R

coollikeabreeze picture coollikeabreeze · Apr 28, 2016 · Viewed 9.9k times · Source

I am plotting a multiple line graph with ggplot2 and am having trouble labeling the y-axis with mile per second squared. I have tried the command:

ggplot(data.frame, aes(id)) + labs(y = "Acceleration in m/s^2")

and( after searching Stack Overflow):

ggplot(data.frame, aes(id)) + labs(y = expression ("Acceleration in m/s[2]")

In both cases, the label does not create superscript, instead looking exactly like "Acceleration m/s^2". How should this superscript command for a ggplot label be constructed?

Answer

joran picture joran · Apr 28, 2016

Try this instead:

 + labs(y = expression ("Acceleration in"~m/s^2))