How can I add a subtitle and change the font size of ggplot plots in R?

后端 未结 2 405
[愿得一人]
[愿得一人] 2021-02-01 17:18

I tried adding a subtitle using +opts(subtitle=\"text\") but nothing showed up. The main title does work (+opts(title=\"text\")).

I would also

2条回答
  •  伪装坚强ぢ
    2021-02-01 17:34

    Update: ggplot version 2.2.0 can do subtitles, as demonstrated e.g. in this blog post.

    Example:

    library(ggplot2)
    packageVersion("ggplot2")  ## 2.2.0
    d <- data.frame(x=1:5,y=1:5)
    ggplot(d,aes(x,y))+
        labs(title="abc",subtitle="def")+
        ## default left-aligned: moved them to center alignment
        theme(plot.title=element_text(hjust=0.5),
              plot.subtitle=element_text(hjust=0.5))
    

提交回复
热议问题