plot_grid function removes axis breaks from ggbreak in plots

804 Views Asked by At

I'm struggling with a problem: I created two volcano plots in ggplot2, but due to the fact that I had one outlier point in both plot, I need to add y axis break for better visualization. The problem arises when I WANT TO plot both in the same page using plot_grid from cowplot::, because it visualizes the original plot without the breaks that I set.

 p<- c1 %>%
     ggplot(aes(x = avg_log2FC,
                y = -log10(p_val_adj),
                fill = gene_type,    
                size = gene_type,
                alpha = gene_type)) + 
     geom_point(shape = 21, # Specify shape and colour as fixed local parameters    
                colour = "black") + 
     geom_hline(yintercept = 0,
                linetype = "dashed") + 
     scale_fill_manual(values = cols) + 
     scale_size_manual(values = sizes) + 
     scale_alpha_manual(values = alphas) + 
     scale_x_continuous(limits=c(-1.5,1.5), breaks=seq(-1.5,1.5,0.5))  +
     scale_y_continuous(limits=c(0,110),breaks=seq(0,110,25))+
     labs(title = "Gene expression",
          x = "log2(fold change)",
          y = "-log10(adjusted P-value)",
          colour = "Expression \nchange") +
     theme_bw() + # Select theme with a white background  
     theme(panel.border = element_rect(colour = "black", fill = NA, size= 0.5),    
           panel.grid.minor = element_blank(),
           panel.grid.major = element_blank()) 
   p1 <- p + scale_y_break(breaks = c(30, 100))
   p1

p plot without breaks: enter image description here

and p1 plot with breaks: enter image description here

The same I did for the second plot. But this is the result using plot_grid(p1,p3, ncol = 2)

enter image description here

Can you help me understanding if I'm doing something wrong? or it is just a limitation of the package?

1

There are 1 best solutions below

0
On BEST ANSWER

OP, it seems in that ggbreak is not compatible with functions that arrange multiple plots, as indicated in the documentation for the package here. There does seem to be a workaround via either print() (I didn't get this to work) or aplot::plot_list(...), which did work for me. Here's an example using built-in datasets.

# setting up the plots
library(ggplot2)
library(ggbreak)
library(cowplot)

p1 <-
ggplot(mtcars, aes(x=mpg, disp)) + geom_point() +
  scale_y_break(c(200, 220))

p2 <-
  ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) +
  geom_point() + scale_y_break(c(3.5, 3.7))

Plots p1 and p2 yield breaks in the y axis like you would expect, but plot_grid(p1,p2) results in the plots placed side-by-side without the y axis breaks.

The following does work to arrange the plots without disturbing the y axis breaks:

aplot::plot_list(p1,p2)

enter image description here