ggplot2 multiline title, different indentations

前端 未结 5 712
失恋的感觉
失恋的感觉 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条回答
  •  感动是毒
    2021-01-01 01:15

    You can use grid.text from package grid, add text to your plot. Firstly add some space above your title use plot.margin.

    library(grid)
    p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species, shape = Species))+
    geom_jitter(size = 6.5)+
    ggtitle("The Actual Long, Normal Title of Titliness")+
    theme(plot.title = element_text(hjust = 0,face = "bold", size = 30),
          axis.ticks = element_blank(),
          legend.text = element_text(size = 25),
          axis.title = element_text(size = 25, face = "bold"),
          axis.text = element_text(size = 25, vjust = 0.05),
          legend.position = "bottom", 
          plot.margin = unit(c(4, 3, 1, 1), "lines"))
    p
    grid.text('A', x = unit(0.1, 'npc'), y = unit(.90, 'npc'), gp = gpar(fontsize=28))
    

提交回复
热议问题