dipetkov / eems

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

Error in make_eems_plots #33

Open tommydevitt opened 5 years ago

tommydevitt commented 5 years ago

I'm able to run the program and visualize the results fine for the most part, however when I try to use m.plot.xy or q.plot.xy to add graphical elements to the plots like so

make_eems_plots(mcmcpath = eems_results,
                longlat = TRUE,
                m.plot = { points(coord, col = "purple") },
                q.plot = { points(coord, col = "purple") }) 

I get:

Error in make_eems_plots(mcmcpath = eems_results, longlat = TRUE, m.plot.xy = { : 
  unused arguments (m.plot.xy = {
    points(coord, col = "purple")
}, q.plot.xy = {
    points(coord, col = "purple")
})

Any suggestions?

Thanks, Tom

dipetkov commented 5 years ago

It is eems.plots, not make_eems_plots. Here is an example: (You can get more examples with ?eems.plots.)

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

datapath <- file.path(extdata_path, "EEMS-example")
coord__long_lat <- read.table(paste0(datapath, ".coord"))

# Add the original sampling locations on top of the contour plot.
eems.plots(mcmcpath = eems_results,
           plotpath = paste0(name_figures, "-sampling-locations"),
           longlat = TRUE,
           m.plot.xy = { points(coord__long_lat, col = "purple", pch=18) },
           q.plot.xy = { points(coord__long_lat, col = "purple", pch=18) })

This is the result:

eems-example-sampling-locations-mrates01

It is important to have the extra coordinates in the same format as the data coordinates. For example, let's flip the longitude/latitude order:

coord__lat_long = coord__long_lat[, c(2,1)]

eems.plots(mcmcpath = eems_results,
           plotpath = paste0(name_figures, "-sampling-locations-flipped"),
           longlat = TRUE,
           m.plot.xy = { points(coord__lat_long, col = "purple") },
           q.plot.xy = { points(coord__lat_long, col = "purple") })

This is the result:

eems-example-sampling-locations-flipped-mrates01

dipetkov commented 5 years ago

After reading your question again, I realize that you want to use reemsplot2. It is possible to add extra graphical elements in this case as well but you have to use ggplot2's geom_* functions.

Here is how to add points for example:

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

# Load the sampling coordinates
coord <- read.table(paste0(eems_results, ".coord"), header = FALSE)
# Name the columns appropriately
if (longlat) {
  colnames(coord) <- c("long", "lat")
} else {
  colnames(coord) <- c("lat", "long")
}

library("ggplot2")

# `make_eems_plots` has no `m.plot.xy` and `q.plot.xy` arguments
# But you can still add more graphical elements on top of the contour plot
plots <- make_eems_plots(mcmcpath = eems_results, longlat = longlat)

# Let's add the original sampling locations to the effective migration surface

plots$mrates01 +
  geom_point(data = coord, aes(x = long, y = lat), shape = 1)

And here is the result:

eems-barrier-mrates01