简体   繁体   中英

Adding exponent to axes labels (R / ggplot2)

I've looked at a number of the solutions to the same question but applied to different datasets, and none seem to work for me.

I'm looking to add metres cubed as the unit for each axis title, with metres cubed obviously showing with an exponent. The latest code I tried (which didn't work) was as follows:

ggplot(data=vol30, aes(x=control, y=vol30)) + geom_point(alpha=.6, size=4, color="#880011") + ggtitle("Ground Survey vs. 30m UAV Survey") + labs(x="Volume, m^{3}", y="Volume, m^{3}") + xlim(0, 5) + ylim(0, 5) + geom_abline(intercept = 0, slope = 1, alpha=.6, size = 1, colour="blue")

I'm new to R and ggplot2, so speak slowly;) Does anyone have any recommendations?

expression应该添加到labs(x =

 x = expression(paste("Volume ", m^{3})), y = expression(paste("Volume ", m^{3}))

你可以使用解析

labs(x=parse(text='Volume, m^3'), y=parse(text='Volume, m^3'))

Having the similar issue, labs(y = "% biomass", x = expression(paste("Mulch amount", tha^{-1})))

It's resulting in no space between mulch amount and tha (making it Mulchamounttha(-1).

Does anyone know how to add space in between

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM