how to subscript the x axis tick label

夙愿已清 提交于 2019-12-05 02:25:36

You want to name the axis in the ggplot definitions. This is not possible at the position where you do it now where you are defining a new name (as a string) for the levels. What happens now is that PM[10] will be recognised and read as a string.

Add this to your ggplot script. This defines the x-axis ticks that you have as a discrete scale:

+ scale_x_discrete("Air pollutant", labels = c(expression(PM[10]),expression(SO[2]), expression(NO), expression(NO[2])))

Have fun.

With thanks to Alexwhan it can also be written as:

+ scale_x_discrete("Air pollutant", labels = parse(text = levels(df$variable)))

Which is even easier.

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