Я пытаюсь построить перепроектированный набор данных, и хотя координаты были перепроецированы, ggplot продолжает использовать систему координат градус-долг-лат.
Вот воспроизводимый пример:
library(sf)
library(dplyr)
library(ggplot2)
set.seed(42)
df <- tibble(lon = runif(20, min = -73, max = -68),
lat = runif(20, min = 41, max = 46))
sf <- st_as_sf(df, coords = c("lon", "lat"), crs = 4326, agr = "constant")
# This plot has the expected lon-lat degree coords
ggplot(sf) + geom_sf()
# Lambert equal-area projection
laea_centered <- "+proj=laea +lat_0=43.15268 +lon_0=-70.30744"
coord_shift <- "+x_0=12019341.4 +y_0=1730136"
proj_ref <- " +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
laea_proj4 <- paste(laea_centered, coord_shift, proj_ref, sep = " ")
sf <- st_transform(sf, crs = laea_proj4)
# Glancing at the data, the transformation appears correct.
sample_n(sf, 5)
# Simple feature collection with 5 features and 0 fields
# geometry type: POINT
# dimension: XY
# bbox: xmin: 75403.74 ymin: 1109827 xmax: 248543.9 ymax: 1660612
# epsg (SRID): NA
# proj4string: +proj=laea +lat_0=-70.30744 +lon_0=43.15268 +x_0=12019341.4 +y_0=1730136 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
# # A tibble: 5 x 1
# geometry
# <POINT [m]>
# 1 (248543.9 1153107)
# 2 (88341.34 1109827)
# 3 (166449.3 1138656)
# 4 (87832.83 1660612)
# 5 (75403.74 1430964)
# Still has geographic coordinates and reticule
ggplot(sf) + geom_sf()
Точки были спроектированы, но на графике все еще используются географические координаты для осей и сетки.
# Same as above, but I wouldn't expect it to be different
# because ggplot takes the crs from the initial data argument.
ggplot(sf) +
geom_sf() +
coord_sf(crs = laea_proj4)