dipetkov / eems

Estimating Effective Migration Surfaces
GNU General Public License v2.0
102 stars 28 forks source link

Error in grid.Call polygon edge not found #32

Open tommydevitt opened 5 years ago

tommydevitt commented 5 years ago

When I include the 'add_outline' argument in reemsplots2:

make_eems_plots(mcmcpath = "barrier-schemeZ-nIndiv300-nSites3000-EEMS-nDemes200-chain1", add_grid = TRUE, add_demes = TRUE, add_outline = TRUE)

I get the following error:

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : polygon edge not found

Any idea what's causing this?

Thanks, Tom

dipetkov commented 5 years ago

To start with, there was an error during building the reemsplots2 package. It seems that's fixed and now I can write the following example:

mcmcpath <- system.file("extdata", "EEMS-barrier", package="reemsplots2")

# Generate contour plots of migration and diversity rates
# as well as several diagnostic plots
plots <- make_eems_plots(mcmcpath, longlat=TRUE, add_grid=TRUE,
                         add_demes=TRUE, col_demes="purple",
                         add_outline=TRUE, col_outline="purple")
names(plots)

library("ggplot2")

plotpath <- file.path(path.expand("~"), "EEMS-barrier")
ggsave(paste0(plotpath, "-mrates01.png"), plots$mrates01,
       dpi=600, width=6, height=4)

And here is the result:

eems-barrier-mrates01

Note: reemsplots2 was a small experiment to learn how to use ggplot2. It doesn't have all the options of the other R package rEEMSplots which uses R basic graphics instead.

dipetkov commented 5 years ago

Testing on some more examples, the "polygon edge not found" error does indeed show up from time to time. This seems to be a known ggplot2 issue: https://github.com/tidyverse/ggplot2/issues/2252.

However, the problem seems to be with rendering the plots, not generating them in the first place. So if you run into this error, I suggest first save the plots to pdf files and then look at the files rather than render the ggplot2 plots directly.

extdata_path <- system.file("extdata", package = "rEEMSplots")
eems_results <- file.path(extdata_path, "EEMS-example")
name_figures <- file.path(path.expand("~"), "EEMS-example")

plots <- make_eems_plots(mcmcpath = eems_results, longlat = TRUE)

for (name in names(plots)) {
    ggsave(paste0(name_figures, "-", name, ".png"), plots[[name]],
           dpi=600, width=6, height=4)
}