I have a Variable named \LW$_\downarrow$ in Latex. As you can imagine, i would like to use the same phrase as axis label and add the Unit which is [W/m²] or [W m^-2]
I managed to do this:
library(ggplot2)
data <- data.frame(x=c(1:5), y=c(2:6))
ggplot(data = data, aes(x=x, y=y))+
geom_point()+
labs(x=expression(LW%down%. ))
but
ggplot(data = data, aes(x=x, y=y))+
geom_point()+
labs(x=expression(LW%down% )) #no point behind the second %
gives "Error:
unexpected ')' in: " geom_point()+ labs(x=expression(LW%down% )"
and
ggplot(data = data, aes(x=x, y=y))+
geom_point()+
labs(x=paste(expression(LW%down%. ), "[W/m²]"))
gives this: with %down% as word
unfortunately not very helpful.
I hope someone can help. I have a lot of plots so I hope someone so manual editing with inkscape does not really sound like a good option.
tyumru gave me a good hint to the right direction with
ggplot(data = data, aes(x=x, y=y))+
geom_point()+
labs(x=expression("LW"%down%"[W/m²]"))
Whe I try to put the arrow in subscript with
ggplot(data = data, aes(x=x, y=y))+
geom_point()+
labs(x=expression("LW"[%down%]"[W/m²]"))
Unfortunately I get
Error: unexpected SPECIAL in: " geom_point()+ labs(x=expression("LW"[%down%"
I guess this is what you are looking for:
ggplot(data = data, aes(x=x, y=y))+
geom_point()+
labs(x=expression("LW"%down%"[W/m²]"))
EDIT:
Ok this is kind of a hack but it works. In the documentation of plotmath you can see that %down% works like an operator, so it requires two strings before and after. The two empy strings serve for that:
ggplot(data = data, aes(x=x, y=y))+
geom_point()+
labs(x=expression(paste(LW[""%down%""]," [W/m²]")))