Giter Site home page Giter Site logo

Unable to add points in rEEMSplots about eems HOT 2 OPEN

dipetkov avatar dipetkov commented on September 5, 2024
Unable to add points in rEEMSplots

from eems.

Comments (2)

tim-oconnor avatar tim-oconnor commented on September 5, 2024

Hi nehasavant -- late reply, but perhaps it'll help you / others. This is absolutely possible, but I've also had issues before. You can just use the "map" or "plot" commands that you want within the m.plot.xy and q.plot.xy arguments. The only trick is to ensure that you first project the points or shapefiles into the same CRS as the EEMS rasters (use spTransform from the sp / rgdal packages).

-Tim

from eems.

dipetkov avatar dipetkov commented on September 5, 2024

Anything inside the m.plot.xy and m.plot.xy is added on top of the raster plot but the statements are not parsed (in order to apply projections, for example). So you have to do it by hand.

Here is the relevant example:

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

library("rgdal")
projection_none <- "+proj=longlat +datum=WGS84"
projection_mercator <- "+proj=merc +datum=WGS84"

# Start with points specified in (longitude, latitude)
coords <- matrix(c(
  -10, 10,
  10, 10,
  30, 0,
  40, -10,
  30, -20
), ncol = 2, byrow = TRUE)
colors <- c("red", "green", "blue", "purple", "orange")
labels <- LETTERS[1:5]

# Transform the coordinates into the same projection
# that will be used to transform the migration rates
coords_merc <- sp::spTransform(
  SpatialPoints(coords, CRS(projection_none)),
  CRS(projection_mercator)
)

# `coords_merc` is a SpatialPoints structure
# but we only need the coordinates themselves
coords_merc <- coords_merc@coords

# So to summarize start with points in one projection
coords
# And project them to the target projection
coords_merc

eems.plots(
  mcmcpath = eems_results,
  plotpath = paste0(name_figures, "-labels-projected"),
  longlat = TRUE,
  projection.in = projection_none,
  projection.out = projection_mercator,
  m.plot.xy = {
    text(coords_merc, col = colors, pch = labels, font = 2)
  },
  q.plot.xy = {
    text(coords_merc, col = colors, pch = labels, font = 2)
  }
)

from eems.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.