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

geom_sf() return values of latitude and longitude for data in a projected coordinate system #2200

Closed
Nowosad opened this issue Jul 12, 2017 · 8 comments
Labels
feature a feature request or enhancement layers 📈

Comments

@Nowosad
Copy link

Nowosad commented Jul 12, 2017

geom_sf() works well in case of data in a geographic coordinate systems - I give graticules and values of latitude and longitude. However, for data in a projected coordinate system, I would expect a plot with values in units of measurement (in this case in meters).
I think that as a default it should return graticules and values of latitude and longitude for data in a geographic coordinate systems and values in units of measurement for data in a projected coordinate system. Additionally, there should be an argument to change it.

library(sf)                                            
#> Linking to GEOS 3.5.0, GDAL 2.1.2, proj.4 4.9.2
library(ggplot2)                                       
                                                       
# decimal degrees                                      
nc = st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source `/home/jn/R/x86_64-redhat-linux-gnu-library/3.4/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> epsg (SRID):    4267
#> proj4string:    +proj=longlat +datum=NAD27 +no_defs
                                                       
ggplot() +                                             
geom_sf(data = nc)                                     

                                                       
# meters                                               
nc_2163 = st_transform(nc, 2163)                       
                                                       
ggplot() +                                             
geom_sf(data = nc_2163)                                

@hadley
Copy link
Member

hadley commented Jul 13, 2017

IIRC the labels just come from sf::st_graticule() so I think this change would have to happen there. Does that sound right @edzer?

@hadley hadley added facets 💎 layers 📈 feature a feature request or enhancement and removed facets 💎 labels Jul 13, 2017
edzer added a commit to r-spatial/sf that referenced this issue Jul 13, 2017
@edzer
Copy link
Contributor

edzer commented Jul 13, 2017

I need to give this a bit more thought on what is the right user interface; this feels a bit like a hack.

But right now,

ggplot() + geom_sf(data = nc_2163) + coord_sf(datum = st_crs(2163))

gives you
x

I think it is not so bad this takes more effort to get, as, in contrast to long/lat, units of this kinds are pretty much meaningless to most people. Maybe it is easier if datum=FALSE or datum=NULL (or both) result in this kind of plot.

@hadley
Copy link
Member

hadley commented Jul 14, 2017

@edzer if you think this is a reasonable default, and there's already a work around, then I'm happy to leave as is.

BTW did you notice that the labels are getting formatted individually instead of collectively? (i.e. 2e+06 vs 1800000)

@hadley hadley closed this as completed Jul 14, 2017
@edzer
Copy link
Contributor

edzer commented Jul 14, 2017

I think I'll go for the NULL or FALSE for datum, and will update the coord_sf documentation accordingly.

For the labels I used as.character(values) - what should I use instead?

@hadley
Copy link
Member

hadley commented Jul 14, 2017

format() might be better, but are you sure there's one call to as.character()? It looks like the result of sapply(x, as.character) vs as.character(x) to me

@edzer
Copy link
Contributor

edzer commented Jul 14, 2017

as.character on the whole vector (actually, on both) see https://github.com/r-spatial/sf/blob/master/R/graticule.R#L146

using format gives the one below, looks identical to me:
xx

doing c(format(lon), format(lat)) doesn't make things any better.

@hadley
Copy link
Member

hadley commented Jul 14, 2017

Oh, you're right! That's super weird:

as.character(7:11 * 2e5)
#> [1] "1400000" "1600000" "1800000" "2e+06"   "2200000"

format() seems to help for me though:

format(7:11 * 2e5)
#> [1] "1400000" "1600000" "1800000" "2000000" "2200000"

@edzer
Copy link
Contributor

edzer commented Jul 14, 2017

the parse loop to digest the degree symbols was the trouble maker.

edzer added a commit to r-spatial/sf that referenced this issue Jul 14, 2017
edzer added a commit to r-spatial/sf that referenced this issue Jul 14, 2017
karawoo pushed a commit that referenced this issue Jul 28, 2017
* addresses #2119

* tidy graticule fixes

* ggplot2 side of issue r-spatial/sf#396

* tabs -> spaces

* add ndiscr to docs

* fix #2200

* attempt to fix #2060

All cases were in sf.R a geometry column is address with x$geometry, ggplot2 made the wrong assumption that the geometry column has a fixed name. I replaced this in certain instances, where the data are already pretty transformed and no longer have properties of sf objects, with a fixed position, i.e. x[[1]], which seems to work.

* fixes r-spatial/sf#438

* address review comments

* fix break on geom_raster, objects without list-column

see https://gist.github.com/mdsumner/573ec70014df177baa2d1df7e55e1943 for the case that this PR fixes

* tidy up

* trying @karawoo's suggestion

* adds some sf tests

* tidy further
@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement layers 📈
Projects
None yet
Development

No branches or pull requests

3 participants