Double facet_grid

Hi, I would like to create a plot where the plots below are above each other. I used facet_grid to create them, can I use it again? If yes, how? Thank you very much!

ggplot(pos8,aes(x=factor(EPG,levels=c("EPP","S&D","ECR","ALDE","GUE/NGL","Greens/EFA","EFFD","ENF")),y=value,color=EPG,weight=seats))+
  geom_jitter(position=position_jitter(width=0.2,height=0),alpha=0.8)+
  geom_boxplot(alpha=0,show.legend=FALSE,lwd=1)+
  scale_color_manual(limits=c("EPP","S&D","ECR","ALDE","GUE/NGL","Greens/EFA","EFDD","ENF"),
                     values=c("#fcdd22","#fc1414","#106da8","#ec008c","#c6262c","#44911d","#00abbc","black"))+
  guides(color=guide_legend(""))+
  theme(legend.position="bottom", 
        axis.text.y=element_blank(),
        axis.ticks=element_blank())+
  labs(x="",y="",title="Figure 2",subtitle="Left-right")+
  facet_grid(variable~.)+
  coord_flip()

What does it mean for some plots to be above 'each other' ?

I think you'd find the functionality you need in this package - https://github.com/thomasp85/patchwork

3 Likes

They would share x-axis and be in the one plot.

Thank you! That is marvelous!

1 Like

Do you know how to have just one legend? (They are not the same, but I could make one comprehensive).

I haven't used this package extensively, so I'm not sure if there is a way, but from what I know it'll only do one legend if legends are exactly the same.

One workaround could be creating extra plot with just legend that would print all of the parties in some way (with geom_text or something). You can then use patchwork to arrange it in whatever layout you need.

Edit: take a look in documentation here - https://patchwork.data-imaginist.com/articles/guides/assembly.html. I'm sure you could adapt one of the examples for what you are doing.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.