Center Plot title in ggplot2

前端 未结 4 1797
臣服心动
臣服心动 2020-12-02 03:31

Hi this simple code (and all my scripts from this morning) has started giving me a off center title in ggplot2

Ubuntu version: 16.04

R studio version: Versi         


        
4条回答
  •  没有蜡笔的小新
    2020-12-02 04:31

    The ggeasy package has a function called easy_center_title() to do just that. I find it much more appealing than theme(plot.title = element_text(hjust = 0.5)) and it's so much easier to remember.

    ggplot(data = dat, aes(time, total_bill, fill = time)) + 
      geom_bar(colour = "black", fill = "#DD8888", width = .8, stat = "identity") + 
      guides(fill = FALSE) +
      xlab("Time of day") +
      ylab("Total bill") +
      ggtitle("Average bill for 2 people") +
      ggeasy::easy_center_title()
    

    Note that as of writing this answer you will need to install the development version of ggeasy from GitHub to use easy_center_title(). You can do so by running remotes::install_github("jonocarroll/ggeasy").

提交回复
热议问题