jfq3 / ggordiplots

Make ggplot Versions of Vegan's Ordiplots
GNU General Public License v2.0
6 stars 2 forks source link

Adjusting height of gg_ordiplots() plot #10

Closed elaine-shen closed 3 years ago

elaine-shen commented 3 years ago

Hello,

I am wondering if there is a way to make the plot from gg_ordiplot() flexible in the vertical direction as you adjust your plot size? It currently seems scale-invariant, which makes it difficult to combine with other ggplot-derived plots. I am currently using ggarrange() to combine my PERMADISP results with the original ordination. Any advice would be greatly appreciated! Screenshots attached of what I mean: Screen Shot 2021-09-16 at 1 03 04 PM Screen Shot 2021-09-16 at 1 03 19 PM

The top image shows the dimensions of my plot screen that are necessary to have all of the x-axes aligned with each other, while the bottom image shows what happens when I make the view screen narrower. When I make the screen narrower, the right ordination and left boxplot automatically adjust to the height of the view screen, while the ordiplot in the center does not fill the vertical space, if that makes sense. Hope my question makes sense, and thanks in advance for your help!

elaine-shen commented 3 years ago

Another more reproducible example can be found in the tutorial provided for Modifying Plots Made with ggordiplots - for the last graph in the tutorial, are the dimensions always fixed (as seems to be the case), and is there a way to adjust that?

data("dune") data("dune.env") dune.bray <- vegdist(dune, method = "bray") ord <- cmdscale(dune.bray, k = nrow(dune) - 1, eig = TRUE, add = TRUE) cl <- hclust(dune.bray, method = "single") clstr.plot <- gg_ordicluster(ord, cluster = cl, plot = FALSE) ellipse.plot <- gg_ordiplot(ord, groups = dune.env$Management, plot = FALSE) ellipse.plot$plot + geom_segment(data = clstr.plot$df_segments, aes(x = x, y = y, xend = xend, yend = yend))

image

jfq3 commented 3 years ago

This happens because my code includes the line plt <- plt + coord_fixed(ratio=1) for all plots. But from my understanding of your question, the difference only happens when you rescale your window. The other plots must not have their ratios fixed at 1. If they did, I think all should remain square when you resize the window. But is this important? I imagine you want to use the figure in a document or presentation. What happens if you save the plot using ggsave()? In that case, I think the the plot window shape should not matter. Try, and let me know.

elaine-shen commented 3 years ago

Hello,

You are ultimately right - I don't think it's that important, I was just trying to figure out what dimension I wanted the final figure to be, and added coord_fixed(ratio=1) to my other graphs so they were all aligned. Thank you for your prompt reply!