Axis title using several fonts

Is it possible to compose a string to be used as axis title in ggplot2, with the main part being drawn using one given font and font size, and the last part being drawn with another font and font size. See below for an example

my axis title (units)

Currently struggling to achieve this.
Thanks in advance for suggestions

Yes, you have to use plotmath annotations. So the text has to be parsed as an expression, and you can use functions such as italics() and bold(). But beware, you can't have spaces, spaces have to be represented with ~ or *.

ggplot(mtcars) +
  geom_point(aes(x=cyl, y=mpg)) +
  xlab(parse(text="bold('My axis title')~' ('*italic('unit')*')'"))

For even more custom text:

2 Likes

Thanks for good and reliable answers. I'll go with ggtext approach that meets more my philosophy.

Changes done and working fine, although support of HTML is quite low thru ggtext.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.