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

Latitude and longitude labels for coord_sf #6265

Closed
Breeze-Hu opened this issue Dec 31, 2024 · 1 comment
Closed

Latitude and longitude labels for coord_sf #6265

Breeze-Hu opened this issue Dec 31, 2024 · 1 comment

Comments

@Breeze-Hu
Copy link

Breeze-Hu commented Dec 31, 2024

I'm not sure if what I'm experiencing is the same problem as this one, again with incomplete labeling of the four positions of latitude and longitude:

library(ggplot2)
library(sf)
library(rnaturalearth)

# Data:
coast <- ne_coastline(scale = 50, returnclass = "sf") 
crs_pr <- "+proj=longlat +lon_0=180 +datum=WGS84  +no_defs"

coast1 = coast |> 
  st_break_antimeridian(lon_0 = 180) |> 
  st_transform(crs_pr)

ggplot(coast1)+
  geom_sf()+
  coord_sf(expand = FALSE,
           xlim = c(st_bbox(coast1)['xmin'], st_bbox(coast1)['xmax']),
           label_axes = list(top = 'E',bottom = "E", left="N",right="N")
           )

The labeled line for latitude is not crossed with the panel boundary.
Image

When a little unreasonable adjustment is made (slightly limiting the range of x), everything works fine:

ggplot(coast1)+
  geom_sf()+
  coord_sf(expand = FALSE,
           xlim = c(st_bbox(coast1)['xmin']+5, st_bbox(coast1)['xmax']-5),
           label_axes = list(top = 'E',bottom = "E", left="N",right="N")
  )
Image It happens even with `expand = FALSE` set, which is weird.

Originally posted by @Breeze-Hu in #2985

This is a similar problem for raster plotting. Even without some projection transformations (compared to the previously mentioned geom_sf data).

library(ggplot2)
library(terra)
library(tidyterra)

#Example data downloaded from NOAA 
https://psl.noaa.gov/mddb2/makePlot.html?variableID=1570
or 
https://psl.noaa.gov/tmp/mddb2/_H5mqysfuv/subset.nc

data <- rast('Path')

ggplot()+
 geom_spatraster(data = data,aes(fill = sst))+
  scale_fill_viridis_c()+
 coord_sf(expand = FALSE,
          label_axes = list(top = 'E',bottom = "E", left="N", right="N"))

Image

@teunbrand
Copy link
Collaborator

Thanks for the report! I think this is the same problem as described in #2985, so I'm going to close this issue in favour of that one.

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

2 participants