Skip to content

x-axis label issue when filtering to 190 degrees (0-360 longitude) #2561

@TiffanyVidal

Description

@TiffanyVidal

When using ggplot with sf the x-axis labels appear to have an issue when the limits include 190 (on the 0-360 scale). When I plot to180, it is fine, and when filtering to 200 degrees, the labels plot fine, but an issue occurs when extending the limit to 190. I have prepped a MWE below.

library(tidyverse)
library(maps)
library(sf)

# Prep the map layer to plot from 0-360
newmap = fortify(maps::map(wrap=c(0,360), plot=FALSE, fill=TRUE))

# Polygon to plot
dat <- st_as_sfc('POLYGON ((170 -10, 200 -10, 200 5, 170 5, 170 -10))',crs = 4326)

# Plot
ggplot() +
  geom_map(data=newmap, map=newmap, aes(map_id=region)) +
  geom_sf(data=dat, fill='gray90', alpha=0.2)+
  theme_bw() +
  coord_sf(xlim = c(130,210), ylim = c(-30,10)) 

ggplot() +
  geom_map(data=newmap, map=newmap, aes(map_id=region)) +
  geom_sf(data=dat, fill='gray90', alpha=0.2)+
  theme_bw() +
  coord_sf(xlim = c(130,190), ylim = c(-30,10))
sessionInfo() R version 4.5.2 (2025-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 11 x64 (build 26100)

Matrix products: default
LAPACK version 3.12.1

locale:
[1] LC_COLLATE=English_Australia.utf8 LC_CTYPE=English_Australia.utf8
[3] LC_MONETARY=English_Australia.utf8 LC_NUMERIC=C
[5] LC_TIME=English_Australia.utf8

time zone: Pacific/Guadalcanal
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] sf_1.0-23 maps_3.4.3 odbc_1.6.3 lubridate_1.9.4 forcats_1.0.1
[6] stringr_1.6.0 dplyr_1.1.4 purrr_1.2.0 readr_2.1.6 tidyr_1.3.1
[11] tibble_3.3.0 ggplot2_4.0.1 tidyverse_2.0.0 readxl_1.4.5

loaded via a namespace (and not attached):
[1] bit_4.6.0 gtable_0.3.6 crayon_1.5.3 compiler_4.5.2
[5] tidyselect_1.2.1 Rcpp_1.1.0 blob_1.2.4 scales_1.4.0
[9] R6_2.6.1 generics_0.1.4 classInt_0.4-11 units_1.0-0
[13] DBI_1.2.3 pillar_1.11.1 RColorBrewer_1.1-3 tzdb_0.5.0
[17] rlang_1.1.6 utf8_1.2.6 stringi_1.8.7 S7_0.2.1
[21] bit64_4.6.0-1 timechange_0.3.0 cli_3.6.5 withr_3.0.2
[25] magrittr_2.0.4 class_7.3-23 grid_4.5.2 rstudioapi_0.17.1
[29] hms_1.1.4 lifecycle_1.0.4 vctrs_0.6.5 KernSmooth_2.23-26
[33] proxy_0.4-27 glue_1.8.0 farver_2.1.2 cellranger_1.1.0
[37] e1071_1.7-16 tools_4.5.2 pkgconfig_2.0.3

sf::sf_extSoftVersion()
GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H PROJ
"3.13.1" "3.11.4" "9.7.0" "true" "true" "9.7.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions