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?
Superscript is “started” by the caret ^ character. Anything after ^ is superscript. The superscript continues until you use a * or ~ character. If you want more text as superscript, then enclose it in quotes.
Changing axis labels To alter the labels on the axis, add the code +labs(y= "y axis name", x = "x axis name") to your line of basic ggplot code. Note: You can also use +labs(title = "Title") which is equivalent to ggtitle .
Creating non-overlapping labels with ggrepel You can also use the same nudge_y arguments to create more space between the labels and the points.
Try this instead:
+ labs(y = expression ("Acceleration in"~m/s^2))
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