Multi line title in ggplot 2 with multiple italicized words

后端 未结 3 549
闹比i
闹比i 2020-12-10 04:59

I am trying to create a plot title manually formatted on two lines which includes two italicized words, I have done some s

3条回答
  •  暖寄归人
    2020-12-10 05:14

    Using a combination of atop, paste, italic and scriptstyle:

    ggplot(mtcars, aes(x = wt, y = mpg)) +
      geom_point() +
      labs(title = ~ atop(paste('First line of title with ',italic("Species")),
                          paste(scriptstyle(italic("Species")),
                                scriptstyle(" secondline words "),
                                scriptstyle(italic("anotherSpecies")),
                                scriptstyle(" the end"))))
    

    gives you the desired result:

    Using scriptstyle is not a necessity, but imho it is nicer to have your subtitle in a smaller font than the main title.

    See also ?plotmath for other usefull customizations.

提交回复
热议问题