-
Notifications
You must be signed in to change notification settings - Fork 2.1k
geom_tile
squares aren't square in geom_sf
plate carrée
#3698
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
Comments
I cannot run your example. The library(ggplot2)
crs = 4326 # https://epsg.io/4326
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot() +
geom_sf(data = nc) +
geom_tile(
aes(x, y, width = 2, height = 2),
data = data.frame(x = -83, y = 34)) +
coord_sf(crs = crs) Created on 2020-01-07 by the reprex package (v0.3.0) Not sure whether this is a problem with ggplot2 or with sf. @edzer? |
|
Huh. Is it possible to get plate carrée by some other means, then, or is that just not implemented for |
Thanks. Oddly, I can't get the transformed library(ggplot2)
library(sf)
crs.lonlat = 4326 # https://epsg.io/4326
nc = sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
nc = st_transform(nc, "+proj=eqc")
d = data.frame(x = -83, y = 34)
d = as.data.frame(st_coordinates(st_transform(
st_as_sf(d, coords = c("x", "y"), crs = crs.lonlat),
"+proj=eqc")))
ggplot() +
geom_sf(data = nc) +
geom_tile(
aes(X, Y, width = 2, height = 2),
data = d) +
coord_sf(crs = "+proj=eqc")
ggsave("/tmp/test.png", width = 3, height = 2) |
Units are now meter, and you're drawing a tile of 2 x 2 m. Try values of 200000 or so. |
That's confusing. It looks like the correspondence between meters and degrees is set at the equator, so each degree is equal to about 40075017 / 360 of the projection's nominal meters, where the numerator is the circumference of the equator in meters. At any rate, I guess my question is answered, so thank you, but you may want to clarify these issues in the documentation of |
With PR #3659 that I'm currently finalizing, this becomes very simple. By default, non-sf geoms now work in long-lat coordinates. library(ggplot2)
library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot() +
geom_sf(data = nc) +
geom_tile(
aes(x, y, width = 2, height = 2),
data = data.frame(x = -83, y = 34)
) +
coord_sf(crs = "+proj=eqc") Created on 2020-02-01 by the reprex package (v0.3.0) |
The same using a different projection. library(ggplot2)
library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot() +
geom_sf(data = nc) +
geom_tile(
aes(x, y, width = 2, height = 2),
data = data.frame(x = -83, y = 34)
) +
coord_sf(crs = 3347) Created on 2020-02-01 by the reprex package (v0.3.0) |
Now that #3659 gets merged, I thought we can close this issue, but it seems I'm closing this anyway, not mainly because the issue is resolved, but because there seems nothing we can do on ggplot2's side. Please correct me if I'm wrong! |
FYI - I don't see any problems using |
Oh, thanks. I see no error, but a different result with the same code as #3698 (comment). I thought this was somehow related to the deprecation of proj4string-notation, but I have no idea. library(ggplot2)
library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1; sf_use_s2() is TRUE
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot() +
geom_sf(data = nc) +
geom_tile(
aes(x, y, width = 2, height = 2),
data = data.frame(x = -83, y = 34)
) +
coord_sf(crs = "+proj=eqc") Created on 2022-08-21 with reprex v2.0.2 |
I saw that too, but this doesn't seem a PROJ problem: if we use My guess is that the
|
I think this is all in agreement with the library(ggplot2)
library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1; sf_use_s2() is TRUE
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot() +
geom_sf(data = nc) +
geom_tile(
aes(x, y, width = 2, height = 2),
data = data.frame(x = -83, y = 34)
) +
coord_sf(crs = "+proj=eqc", default_crs = st_crs(4326)) |
Yes, you are right. Sorry, it seems I was a bit confused. I tired some combination of library(ggplot2)
library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1; sf_use_s2() is TRUE
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot() +
geom_sf(data = nc) +
geom_tile(
aes(x, y, width = 2, height = 2),
data = data.frame(x = -83, y = 34)
) +
coord_sf(crs = st_crs(4087), default_crs = st_crs(4326)) Created on 2022-08-21 with reprex v2.0.2 |
When a I draw a square with
geom_tile
in a plot withcoord_sf(crs = 4326)
, the result appears taller than it is wide. Maybe there's a problem withgeom_tile
, or maybecoord_sf(crs = 4326)
isn't actually using plate carrée (in which one degree of longitude is the same length as one degree of latitude). I'm not sure which.#3654 is possibly related.
The text was updated successfully, but these errors were encountered: