courtiol / IsoriX

This is the website dedicated to the development of the R package IsoriX
12 stars 5 forks source link

Plotting multiple group assignments in the same figure #92

Closed PatWright closed 6 years ago

PatWright commented 6 years ago

I was wondering what would be the best way to view multiple group assignment isoscapes in the same figure. I have samples from n sites that were sampled at different points in time (so based on different isoscapes) and would like to view them together a bit like plotting the assignment of several individuals at once.

courtiol commented 6 years ago

There are multiple ways to do that. One simple way is to use the package gridExtra. E.g.

plot1 <- plot() ## here is the call to one IsoriX plot
plot2 <- plot() ## here is the call to another IsoriX plot
grid.arrange(plot1, plot2, ncol=2)

That should work because the main plotting functions in IsoriX return the lattice plot invisible, that means that if you use <- you retrieve the plot and can work on it using lattice or package working with lattice. Let me know if that does not work. We should include that in some vignette...

PatWright commented 6 years ago

Thanks. That method works for me when I plot a few maps. I was trying something similar previously but I think grid.arrange struggles to plot 12 isoscapes together.

courtiol commented 6 years ago

I don't think that grid.arrange is the culprit. If you would do that with empty plots, it should work. The issue is probably that the plots have too high resolution and thus require too much memory to be plotted. You can quickly check that be rerunning your workflow after lowering the resolution using relevate() with higher aggregation factor.

To plot high resolution maps, I would try not to display them directly but to create a pdf (or other kind of output). For this, use the argument plot = FALSE in the calls to plot().

So, something like:

plot1 <- plot(..., plot = FALSE)
plot2 <- plot(..., plot = FALSE)

pdf("myplot.pdf")
grid.arrange(plot1, plot2, ncol=2)
dev.off()

++

alex

PatWright commented 6 years ago

Yes, it is more to do with the amount of memory I'm using than grid.arrange. Plotting on the pdf does make it quicker, but the number of maps make it hard to visualize (see pdf). Do you have any suggestions to make it look better? myplotSpgAut.pdf

courtiol commented 6 years ago

Two options given by ?pdf: