0

I have two plots, which have good proportions of the plot itself and the text of the x-axis. [enter image description here][1] and [enter image description here][2]

However, when I combine them into one plot using plot_grid function, the text of the x-axis take a much larger proportion of the combined plot. [enter image description here][3]

How can I combine the plots while saving or controlling the proportions of the x-axis versus the plots themselves WITHOUT making the text smaller?

Here is my code:

  ggplot(variance_birds, aes(x=reorder(Species, order), precentage)) +
  geom_point(aes(shape=type), colour = 'black', size = 3, stroke = 1.5) +
  theme(axis.text.y = element_text(size = 18, colour = 'black'),
        axis.text.x = element_text(size = 14, angle = 70, colour = 'black', 
                                   vjust = 0.97,  hjust = 1),
        axis.title.y = element_text(size = 18, colour = 'black'),
        legend.title = element_blank(), legend.position = "none",
        legend.text = element_text(size=15),
        panel.background = element_rect(fill = 'white', colour = 'black'),
        panel.border = element_rect(colour = "black", fill=NA, size=.5))+
  scale_shape_manual("", values=c("mean"=20,
                              "mean_range"=17))+
  scale_y_continuous(breaks=c(0, 10, 20, 40, 60, 80, 100), limits = c(0, 100))+
  geom_segment(aes(x=Species,xend=Species, y=min,yend=max),inherit.aes=FALSE,
               linetype="longdash", color="black", size=0.55)+
  labs(x=NULL, y="Percentage of species-typical breeding units\nwith helpers in a population")+
  theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"))+
  draw_label("Birds", x = 2.1, y = 100, size = 20, fontface="bold")


p_birds

##Plot mammals

p_mammals<-
  ggplot(variance_mammals, aes(x=reorder(Species, order), precentage)) +
  geom_point(aes(shape=type), colour = 'black', size = 3, stroke = 1.5) +
  theme(axis.text.y = element_text(size = 18, colour = 'black'),
        axis.text.x = element_text(size = 14, angle = 70, colour = 'black',
                                   vjust = 0.97,  hjust = 1),
        axis.title.y = element_text(size = 18, colour = 'black'),
        legend.title = element_blank(), legend.position = "none",
        legend.text = element_text(size=15),
        panel.background = element_rect(fill = 'white', colour = 'black'),
        panel.border = element_rect(colour = "black", fill=NA, size=.5))+
  scale_shape_manual("", values=c("mean"=20,
                                  "mean_range"=17))+
  scale_y_continuous(breaks=c(0, 10, 20, 40, 60, 80, 100), limits = c(0, 100))+
  geom_segment(aes(x=Species,xend=Species, y=min,yend=max),inherit.aes=FALSE,
               linetype="longdash", color="black", size=0.55)+
  labs(x=NULL, y="Percentage of species-typical breeding units\nwith helpers in a population")+
  theme(plot.margin=unit(c(1,1,1,1),"cm"))+
  draw_label("Mammals", x = 2.9, y = 92, size = 20, fontface="bold")

p_mammals+
  draw_label("'", x = 14.3, y = -30.5, angle=70, size = 20, colour="black")+
  coord_cartesian(ylim = c(0, 100), clip = "off")


#combining the two plots

combined_plot<-plot_grid(p_mammals+ theme(legend.position = 'none'),
                        p_birds+ theme(legend.position = 'none'),
                       align = "h", ncol = 1, rel_heights = c(5/10, 5/10))

combined_plot```

Thanks!

  [1]: https://i.stack.imgur.com/FOFn6.jpg
  [2]: https://i.stack.imgur.com/sf7In.jpg
  [3]: https://i.stack.imgur.com/h1s8V.jpg
  • check out this post: https://stackoverflow.com/questions/18427455/multiple-ggplots-of-different-sizes – Pedro Alencar Nov 01 '21 at 09:37
  • Does this answer your question? [Multiple ggplots of different sizes](https://stackoverflow.com/questions/18427455/multiple-ggplots-of-different-sizes) – Pedro Alencar Nov 01 '21 at 09:38
  • you should really be making this plot by combining the datasets and using facetting to get the separate panels. – George Savva Nov 01 '21 at 09:45
  • Thanks @GeorgeSavva. that looks like an easy solution. BUT, I still want to have a separate x-axis for each plot. Right under each of them. Can I do that with faceting? – Yitzchak Ben-Mocha Nov 01 '21 at 10:00
  • Thanks, @PedroAlencar. But it doesn't really make a difference. I still have the same problem even when using grid.arrange. – Yitzchak Ben-Mocha Nov 01 '21 at 10:12
  • @YitzchakBen-Mocha yes use `facet_wrap` with the `scales="free_x"` option – George Savva Nov 01 '21 at 10:47
  • Also, consider flipping the axes so that the discrete axis is vertical and the quant axis is horizontal. You will find it much easier to fit everything in that way. – George Savva Nov 01 '21 at 11:02

1 Answers1

0

Actually, adding this was the simplest solution: ggsave("Figure 2.pdf", width = 40, height = 50, units = "cm") Thanks for helping though!