ggplot2: Font Style in label expression
Solution 1:
I do not think it is the presence of expression
, although you don't say exactly what it is that you are seeing so it's difficult to be sure. On a Mac you get the xlab in bold-serif font, but the ylab is not bold (although it is in serif). If I use the plotmath bold
it succeeds from inside the expression function:
p <- ggplot(data = mtcars, aes(x=wt, y=mpg)) +
geom_point() +
labs(x = "Weight", y = expression(bold(mpg (m^-2) ))) +
theme(axis.title.y = element_text(family="serif",
size = 12, angle = 90, vjust = 0.25)) +
theme(axis.title.x = element_text(family="serif",
size = 12, angle = 0, hjust = 0.54, vjust = 0))
p
As always, graphical devices are often OS-variable and you have not offered any hint about yours, so further commentary is inhibited.
(EDIT: If you quote the exponent -2 you can get it bold()-ed as well.)
expression( bold(mpg (m^bold("-2")) ) ) )