Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data plotted outside 180° line with the Equal Earth and Kavrayskiy V projections #115

Open
pvjeetze opened this issue Sep 22, 2023 · 0 comments

Comments

@pvjeetze
Copy link

pvjeetze commented Sep 22, 2023

When I'm plotting global raster data with geom_spatraster using the Equal Earth or Kavrayskiy V projections, the data is duplicated outside the 180° line. With other equal area projections such as the Eckert IV, plotting works like charm.

image

Behaviour is as expected with the vector data (country and land borders).

Code excerpt:

library(terra)
library(tidyterra)

coordRefSys <- "+proj=eqearth"

countrPoly <- vect(file.path(dirPoly, "countries.shp"))
countrPoly <- crop(countrPoly, ext(-179.99, 179.99, ymin(countrPoly), ymax(countrPoly )))
landPoly <- aggregate(countrPoly, dissolve = TRUE)

rusleRast <- rast(file.path(dirRast, "RUSLE_Baseline_2020_30s.tif"))
# Here I tried clipping data along 180°, but to no avail
# rusleRast <- crop(rusleRast, ext(-179,179,ymin(rusleRast), ymax(rusleRast)))

rusle <- ggplot() +
  geom_spatvector(
    data = landPoly, fill = "grey90", colour = NA
  ) +
  geom_spatraster(data = rusleRast, maxcell = 1e+6) +
  scale_fill_gradientn(
    colours = c("darkgreen", "yellow", "tomato3"),
    values = rescale(c(0, 1, 3, 5, 10, 20, 50)),
    limits = c(0, 50),
    breaks = c(0, 1, 3, 5, 10, 20, 50),
    na.value = NA,
    labels = c("0 - 1", "1 - 3", "3 - 5", "5 - 10", "10 - 20", "20 - 50", ">50"),
    name = expression(atop("Soil loss by water erosion [Mg ha"^-1 * " year"^-1 * "]"))
  ) +
  geom_spatvector(
    data = countrPoly, fill = NA, colour = "black", linewidth = 0.25
  ) +
  coord_sf(crs = coordRefSys, clip = "on") 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant