I try to generate a label with superscript and therefore using parse. I seem to cannot use whitespaces, this works:
GTVol <- 1:10
measuredVol <- 1:10
dat <- data.frame(GTVol, measuredVol)
ggplot(dat, aes(GTVol, measuredVol)) +
geom_point() +
geom_abline(slope=1) +
xlab(parse(text='HarvestedVolume(m^3)')) +
ylab("QSM Volume (m^3)")
but this is not working:
GTVol <- 1:10
measuredVol <- 1:10
dat <- data.frame(GTVol, measuredVol)
ggplot(dat, aes(GTVol, measuredVol)) +
geom_point() +
geom_abline(slope=1) +
xlab(parse(text='Harvested Volume (m^3)')) +
ylab("QSM Volume (m^3)")
giving me the following error:
Error in parse(text = "Harvested Volume (m^3)") :
<text>:1:11: unexpected symbol
1: Harvested Volume
Change the space character by adding ~
library(ggplot2)
ggplot(dat, aes(GTVol, measuredVol)) +
geom_point() +
geom_abline(slope=1) +
xlab(parse(text='Harvested~Volume~(m^3)')) +
ylab("QSM Volume (m^3)")
-output

Or use gsub for dynamic replacement
...
xlab(parse(text=gsub("\\s+", "~", 'Harvested Volume (m^3)'))) +
...
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