Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ggOceanMaps for plotting on both sides of the 180 dateline

Tags:

r

maps

ggplot2

I'm trying to make a map of NZ and the Chatham Islands similar to this one specifically using the package ggOceanMaps (bc I need that style of bathymetry) and the function basemaps().

However, the function doesn't allow me to go over the dateline. Is there anyway around this?

This is the code I've got:

install.packages(c("ggOceanMapsData", "ggOceanMaps"), 
                 repos = c("https://cloud.r-project.org", "https://mikkovihtakari.github.io/drat")
)
library(ggOceanMaps)

nzmap1<-basemap(limits = c(165, 180, -32, -51), bathymetry = TRUE,resolution = "high",
               land.col="darkseagreen4",lon.interval = 5,lat.interval = 5)+
               xlab("Longitude")+ylab("Latitude")
nzmap1

So it works fine from 165 to 180 degrees longitude, but if I try go beyond 180/-180 (ideally I'd like to go to -170) it comes out with the error code:

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

Thanks, Tory

like image 632
Victoria Carrington Avatar asked Oct 18 '25 02:10

Victoria Carrington


1 Answers

The limits you choose lead to a decimal degree CRS. When decimal degrees are plotted in two cartesian dimensions, maps cannot be plotted across the antimeridian without changing the definition of the CRS (the step from 180 to -180 is not continuous and hence cannot be plotted on the x-axis without modifying the scale).

To counter this issue, you can the Antarctic stereographic projection:

library(ggOceanMaps)

packageVersion("ggOceanMaps")
#> [1] ‘1.1.10’

basemap(limits = c(165, -170, -32, -51), shapefiles = "Antarctic",
        bathymetry = TRUE, lon.interval = 5, rotate = TRUE)

#> Using lon and lat as longitude and latitude columns, respectively.
#> projection transformed from EPSG:4326 to +proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=177.5 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
#> Warning message:
#> In sp::proj4string(eval(parse(text = shapefiles$land))) :
#>  CRS object has comment, which is lost in output

enter image description here

Read more here

like image 169
Mikko Avatar answered Oct 19 '25 17:10

Mikko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!