sf icon indicating copy to clipboard operation
sf copied to clipboard

y-axis labels missing in plot crossing date line

Open edzer opened this issue 6 years ago • 2 comments

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 avatar Nov 02 '18 15:11 edzer

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

edzer avatar Nov 02 '18 15:11 edzer

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)

DanOvando avatar Feb 20 '20 21:02 DanOvando