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
Affine transformation using mutate()
#903
Comments
With this, your first "does not work" should now work, I assume that was what you were looking for. Note the newly created ambiguity of library(sf)
# Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3
sfc = st_sfc(st_point(0:1), st_point(2:3))
sfc + c(2,3) # add single 2D point to EACH geometry
# Geometry set for 2 features
# geometry type: POINT
# dimension: XY
# bbox: xmin: 2 ymin: 4 xmax: 4 ymax: 6
# epsg (SRID): NA
# proj4string: NA
# POINT (2 4)
# POINT (4 6)
sfc * c(2,3) # first geometry multiplied by 2, second by 3
# Geometry set for 2 features
# geometry type: POINT
# dimension: XY
# bbox: xmin: 0 ymin: 2 xmax: 6 ymax: 9
# epsg (SRID): NA
# proj4string: NA
# POINT (0 2)
# POINT (6 9) Cc: @mdsumner |
Ugh- yeah that's a bit of a screwdriver in the works, I don't see a good solution |
I documented it. |
Oh great, thanks for doing this @edzer ! |
I've tested it on a few cases and it worked as expected. It is a great improvement. @edzer should I open a new issue on ggplot2 or keep it here? library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.3.2, PROJ 4.9.3
library(dplyr)
library(spData)
new_nz = nz %>%
mutate(scale = seq(0.2, 1, length.out = nrow(nz))) %>%
mutate(geom = geom * scale)
# plotting ----------------------------------------------------------------
library(tmap)
library(ggplot2)
# base plot ---------------------------------------------------------------
plot(new_nz["Median_income"]) # tmap plot ---------------------------------------------------------------
tm_shape(new_nz) + tm_polygons("Median_income")
#> Warning: Current projection of shape new_nz unknown and cannot be
#> determined.
#> Warning: unknown projection
#> Legend labels were too wide. The labels have been resized to 0.26, 0.26, 0.26, 0.26, 0.26, 0.26. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger. # ggplot ------------------------------------------------------------------
ggplot() + geom_sf(data = new_nz, aes(fill = Median_income)) Created on 2018-11-25 by the reprex package (v0.2.1) |
Let's try to sort out what happens first. IIRC, by transforming it |
Forget my previous message: it looks like |
Which I just did: 9fe41f2 . Sorry for the bad news. |
It's not an anti meridian problem? |
No, everywhere -- I think it is in |
Just for the reference - https://github.com/tidyverse/ggplot2/blob/828e948dcfc5c5a2bd532e78b160bb3abb25de74/R/sf.R#L748 |
Looks good now: library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.3.2, PROJ 4.9.3
library(dplyr)
library(spData)
new_nz = nz %>%
mutate(scale = seq(0.2, 1, length.out = nrow(nz))) %>%
mutate(geom = geom * scale)
# plotting ----------------------------------------------------------------
library(tmap)
library(ggplot2)
# base plot ---------------------------------------------------------------
plot(new_nz["Median_income"]) # tmap plot ---------------------------------------------------------------
tm_shape(new_nz) + tm_polygons("Median_income")
#> Warning: Current projection of shape new_nz unknown and cannot be
#> determined.
#> Warning: unknown projection
#> Legend labels were too wide. The labels have been resized to 0.26, 0.26, 0.26, 0.26, 0.26, 0.26. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger. # ggplot ------------------------------------------------------------------
ggplot() + geom_sf(data = new_nz, aes(fill = Median_income)) Created on 2018-11-25 by the reprex package (v0.2.1) |
@edzer It looks good for me. Should I close the issue or there is still something related that needs to be tested? |
Continuing a discussion from twitter (https://twitter.com/edzerpebesma/status/1066051809347870720):
The main idea is to allow each feature to be scaled independently:
Created on 2018-11-24 by the reprex package (v0.2.1)
The text was updated successfully, but these errors were encountered: