MikkoVihtakari / ggOceanMaps

Plot oceanographic research data on maps using ggplot2
GNU General Public License v3.0
46 stars 7 forks source link

Plotting extent changed by reorder_layers function #21

Closed mkmor closed 1 year ago

mkmor commented 1 year ago

I would like to plot the basemap land layers on top of my vector polygon layers in ggplot, but I think there is a bug in the function that I hope can be worked out.

library(ggOceanMaps)

p = basemap(limits=c(-92, -47, 40, 79),
        projection.grid = TRUE, grid.col=NA, rotate=T,
        land.border.col = "darkgrey", land.col = "lightgrey")

p

original_map

reorder_layers(p)

reorder_layers

When I run the reorder_layers() function, the plotting extent becomes centered over the prime meridian rather than remaining as the specified extent in the original map variable. It looks like it might have to do with the CRS projection perhaps, as the lat/long units are different in the second map.

I haven't included any of the vector layers because the same thing happens when I am only plotting the base map. Any ideas how this can be fixed?

MikkoVihtakari commented 1 year ago

Yes, this indeed seems like a bug. Thanks reporting. I am busy now, but will flag this issue and look at it when I have time. No promises before the summer.

If you turn rotate = FALSE, it works. The rotate algorithm is a hack and does not work properly always.

MikkoVihtakari commented 1 year ago

Fixed with this: https://github.com/MikkoVihtakari/ggOceanMaps/commit/012894cb0863ec5e73339ca8ccc7633e3f0dd6e0

At the moment of writing, install from a separate developmental branch: https://github.com/mikkovihtakari/ggoceanmaps/tree/sf-version (This branch will be made master and uploaded to CRAN once the conversion is complete).

library(ggOceanMaps)
#> Loading required package: ggplot2
#> ggOceanMaps: Setting data download folder to a temporary folder
#> /var/folders/9v/b70pd53x04d3jjmlrbcgp4_w0000gv/T//RtmpEDia7L. This
#> means that any downloaded map data need to be downloaded again when you
#> restart R. To avoid this problem, change the default path to a
#> permanent folder on your computer. Add following lines to your
#> .Rprofile file: {.ggOceanMapsenv <- new.env(); .ggOceanMapsenv$datapath
#> <- 'YourCustomPath'}. You can use usethis::edit_r_profile() to edit the
#> file.'~/Documents/ggOceanMapsLargeData'would make it in a writable
#> folder on most operating systems.
packageVersion("ggOceanMaps")
#> [1] '1.4.0'

p = basemap(limits=c(-92, -47, 40, 79), rotate=T)

p


reorder_layers(p)

Created on 2023-06-26 with reprex v2.0.2