r-spatial / sf

Simple Features for R
https://r-spatial.github.io/sf/
Other
1.33k stars 293 forks source link

y-axis labels missing in plot crossing date line #882

Open edzer opened 5 years ago

edzer commented 5 years ago

Reported by @basille on twitter:

library(sf)
library("rnaturalearth") 
library("rnaturalearthdata") 
world <- ne_countries(scale = "medium", returnclass = "sf") 
library(ggplot2) 

ggplot(data = world) +
    geom_sf() +
    coord_sf(crs = "+init=epsg:3832", xlim = c(-.3e7, 1.7e7), ylim = c(-1.2e7, .8e7))

gives x

where the y axis labels are missing. Seems to be a problem with sf::st_graticule, since

plot(st_transform(world[,1], 3832), xlim = c(-.3e7, 1.7e7), ylim = c(-1.2e7, .8e7), axes=T, reset=F, graticule = TRUE)

gives y

edzer commented 5 years ago

Closed through https://github.com/r-spatial/sf/commit/84698a6894915854119d2cd266544f850307b583

DanOvando commented 4 years ago

Hmm I'm still having this problem of missing labels when crossing date line

macOS Catalina 10.15.2 latest version of gdal installed via homebrew sf installed from source, version 0.8.1

library(tidyverse)
library(sf)
#> Linking to GEOS 3.8.0, GDAL 2.4.4, PROJ 6.3.1
library(rnaturalearth)

packageVersion("sf")
#> [1] '0.8.1'

hawaii_map <- ne_states(country = "united states of america",
                        returnclass = "sf") %>%
  filter(name == "Hawaii") 

example <-
  expand_grid(lon = c(-179.5,-123.5), lat = c(0.5, 38.5)) %>%
  mutate(thing = 10)

# y-axis labels appear
ggplot() +
  geom_sf(data = hawaii_map, fill = "brown")


# y-axis labels missing
ggplot() +
  geom_sf(data = hawaii_map, fill = "brown") +
  geom_point(data = example, aes(lon, lat, color = thing))


# y-axis labels appear (we should certainly hope)

ggplot() +
  geom_point(data = example, aes(lon, lat, color = thing))


# changing projection creates a new problem

hawaii_map <- ne_states(country = "united states of america",
                        returnclass = "sf") %>%
  filter(name == "Hawaii") %>% 
  sf::st_transform(crs = "+init=epsg:3832")

ggplot() +
  geom_sf(data = hawaii_map, fill = "brown") +
  geom_point(data = example, aes(lon, lat, color = thing))

Created on 2020-02-20 by the reprex package (v0.3.0)