Having issue adding space, I am using the following to name my x and y title.
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 using the same code style?
CodePudding user response:
From ?plotmath
‘x ~~ y’ put extra space between x and y
plot(0:1, 0:1, xlab = expression("Mulch amount"~~tha^{-1}))
Or you could include the space in your string
plot(0:1, 0:1, xlab = expression("Mulch amount "*tha^{-1}))
(since the *
operator does juxtaposition, I often use it as a shortcut for paste()
)
CodePudding user response:
You can use a tilde (~) in your expression to leave a gap between unquoted variable names, or an asterisk (*) to have them adjacent without a gap.
library(ggplot2)
ggplot(mtcars, aes(wt, mpg))
geom_point()
labs(y = "% biomass", x = expression(Mulch~amount~tha^{-1}))
Created on 2022-09-19 with reprex v2.0.2