“Squared” superscript in ggplot2 yaxis label in R

时光毁灭记忆、已成空白 提交于 2019-12-10 18:46:32

问题


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?


回答1:


Try this instead:

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


来源:https://stackoverflow.com/questions/36920492/squared-superscript-in-ggplot2-yaxis-label-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!