0

I have two plots I'm trying to present together using ggarrange, but y grid lines disappear when doing so using common.legend = TRUE.

Here's how it looks without common.legend = TRUE:

ggarrange(p1,p2)

enter image description here

Setting a common legend results in this:

ggarrange(p1,p2,common.legend = TRUE)

enter image description here

Any ideas why this is happening and how to avoid it?

Stars
  • 25
  • 4
  • Have you considered using the patchwork package for plot composition? Also, please include code and (dummy) data in your question so that we might reproduce the problem. – teunbrand Feb 21 '21 at 22:06

2 Answers2

0

I am unable to reproduce the problem.

Please see How to make a great R reproducible example and provide the necessary code to reproduce the issue, then we can provide potential solutions.

library(tidyverse)
library(palmerpenguins)
library(ggpubr)

p1 <- penguins %>% 
  na.omit() %>%
  ggplot(aes(x = flipper_length_mm,
             y = bill_length_mm / max(bill_length_mm),
             colour = island)) +
  geom_line() +
  theme_minimal(base_size = 16) +
  theme(panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.minor.y = element_blank())

p2 <- penguins %>% 
  na.omit() %>%
  ggplot(aes(x = bill_depth_mm,
             y = bill_length_mm / max(bill_length_mm),
             colour = island)) +
  geom_line() +
  theme_minimal(base_size = 16) +
  theme(panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.minor.y = element_blank())

ggarrange(p1, p2)

example_1.png

ggarrange(p1, p2, common.legend = TRUE)

example_2.png

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
0

I found the problem - I used theme_classic() in both individual plots, the problem was solved when I removed it, so now the unified plot looks like this: enter image description here

I still can't understand why this problem occurred, but at least I managed to find a way around it.

Stars
  • 25
  • 4