ggpubr icon indicating copy to clipboard operation
ggpubr copied to clipboard

annotate_figure titles overlap ggplot titles

Open morrisseyj opened this issue 2 years ago • 0 comments

When joining a number of ggplot figures using ggpubr the titles generated in ggplot (using labs()) overlap with the title generated in annotate_figure (using fig.lab =).

Example:

#import libraries

library(ggplot2)
library(ggpubr)
#create data
data <- data.frame('type' = c('A', 'B', 'C'), 
                   'value' = c(1, 2, 3))
#create figure
fig <- ggplot(data, 
              aes(x = type, y = value)) + 
  geom_point() +
  labs(title = 'My title') +
  theme(plot.title = element_text(hjust = 0.5))
        
#arrange figure (in my real case i would actually be sticking plots together)       
arrange_fig <- ggarrange(fig)

#annotate plots
annotate_figure(arrange_fig,
  fig.lab = 'My main title',
  fig.lab.pos = 'top')

w7WCK

I realize in my example, i don't need to center the ggplot title, but in my real case, I arrange three plots, each with a title and these then clash with the annotate_figure title (fig.pos =). This would be the case regardless of where I position the annotate_figure title. Effectively I need to move it 'up'.

Issue also posted on SO (https://stackoverflow.com/questions/73914344/annotate-figure-titles-overlap-ggplot-titles): proposed solution is to use patchwork. I was wondering if there was a ggpubr solution.

morrisseyj avatar Oct 05 '22 19:10 morrisseyj