ggplot2 multiline title, different indentations

前端 未结 5 711
失恋的感觉
失恋的感觉 2021-01-01 00:25

I am generating graphs for a publication and I\'d like to be able to label the panels of a figure in ggplot itself (as opposed to exporting to publisher, etc) so that they j

5条回答
  •  猫巷女王i
    2021-01-01 00:57

    Update: Since ggplot2 3.0.0 there is now native support for plot labels, see this answer.

    Here is how I would do it, using the cowplot package that I wrote specifically for this purpose. Note that you get a clean theme as a bonus.

    library(cowplot)
    
    p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species, shape = Species)) +
      geom_jitter(size = 3.5) +
      ggtitle("The Actual Long, Normal Title of Titliness")
    
    # add one label to one plot
    ggdraw(p) + draw_plot_label("A")
    

    # place multiple plots into a grid, with labels
    plot_grid(p, p, p, p, labels = "AUTO")
    

    You then want to use the save_plot function to save plots instead of ggsave, because save_plot has defaults and parameters that help you get the scaling right relative to the theme, in particular for plots in a grid.

提交回复
热议问题