Search code examples
rggplot2facet

stack ggplot objects without repeating facets names


I am using the same facets to divide into stations my dataset. I have done three graphs this way, and I would like to arrange the three graphs in a single plot, I have done it with ggarange() in ggpubr, but I'd like to remove the facet labels because they are redundant (keep them in the first row only). I'll show a minimal reproducible example with dataset iris:

ggarrange(
 ggplot(data=iris, aes(x=Sepal.Length, y=Petal.Length))+ geom_point()+facet_wrap(~Species)+theme(legend.position = "none"),
 ggplot(data=iris, aes(x=Sepal.Length, y=Petal.Width))+ geom_point()+facet_wrap(~Species)+theme(legend.position = "none"), #"bottom"),
 ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width))+ geom_point()+facet_wrap(~Species)+theme(legend.position = "bottom"),
 nrow = 3 
)

It would be like this. setosa, vresicolor and virginica appear several times, which is redundant

I want to take out the facet labels in rows 2 and 3 since it is redundant.

Thank you.


Solution

  • I would take this in a different approach
    First put your data in a correct format, and then facet using 2 variables.

    require(tidyr)
    iris2 <- iris %>% gather(variable, value, Sepal.Width:Petal.Width)
    
    ggplot(data=iris2, aes(x=Sepal.Length, y=value)) + 
      geom_point() + 
      facet_grid(variable~Species)
    

    enter image description here