-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Mark geom_map() as superseded #3721
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
One thing in my mind is |
Agreed, those ongoing pull requests are definitely needed to replace geom_map(). Thanks. |
Maybe, sf_data() is needed to transform data.frame to sf for geom_sf(), just as map_data() did for geom_map(). It can be another solution for #3659 , #3655 and #3654. As I mentioned, #3655 (comment), it is a issue about data, so just handle the data. |
Isn't this can be done with st_as_sf(coords = c("x", "y"))...? |
1.st_as_sf() can only output point(s), if the input is a data.frame. 2.Sf indeed supply more constructor, such as st_linestring and st_polygon, to create a line or polygon. 3.So, a light weighted and user friendly sf_data() would be needed. it may be sth like: sf_data(data, coords = c("x", "y"), crs = 4326, group = NULL, subgroup = NULL, type = c("point", "line", "polygon")) data, a data.frame This is a tentative suggestion, please forgive me if it is wrong~ |
@microly I agree with your general thoughts on this, but I'd like to propose a different approach: How about a |
Ah, makes sense. But, I'm a bit skeptical about implementing it in ggplot2. IIUC, in the pre-sf days, we needed to define ggplot2's own convention about the map data and provide the utilities (like various
Sounds good. But, isn't it possible to convert data.frame transparently in |
@clauswilke @yutannihilation |
I feel the geometry column should be determined before stat. Probably it also can be done in the stat step, but Lines 29 to 37 in 0183011
|
@yutannihilation Another geom seems to be needed. As I see, a lot of ggplot2 users do not have enough knowlege about spatial data object, such as sf. |
Just like the author of #3717, a lot of ggplot2 users know few about sf. |
@yutannihilation When you say "so we don't need another geom", do you mean we just modify |
@clauswilke We can just refactor the geom_map(). |
@microly @clauswilke |
Yeah, I don't think modifying
|
Let me clarify. One of the reasons I opened this issue was you suggested discouraging use of |
A lot of code out in the wild uses In conclusion: I'm not sure what the best approach is. Maybe provide a geom that can take the same input data as |
I think geom_map() is still useful for the users who know few about sf and want to draw a map using data.frame as succinctly as possible. In sum, geom_map() is useful in the sense that users may want to draw a map layer using data.frame. But geom_map() need a deep refactoring, such as adding a StatMap. |
How about this:
|
This indicated that more geoms should be added, such as geom_point_map() and geom_line_map() to darw the map layer of point(s) and line(s). It seems not so good... |
In sum, there are 2 problems:
line and polygon need a identifier (eg. id or group) other than xy coords. |
We may be going round in circles now: I think I have to finish up #3659 first, as it will resolve a lot of these issues. For example, |
Thanks.
I see... I don't think we can remove |
Btw, apart from the discussion about data.frame, I was wondering about if there's any use cases of |
How about create a new stat? For drawing points: For drawing lines: For drawing polygons: For drawing polygons with holes: |
Sp can hold one or some kinds of wired spatial data structure, which cannot be represented by sf. I saw this message somewhere, but I am sorry that I forget where and I do not know whether it is still true now. |
Yeah, I vaguely know not all sp data can be represented by simple features. What I'm wondering is that there are any cases when such data can still be handled by |
I believe that these cases are very very few. |
None of this is necessary if we merge #3659, since all regular geoms work with it. I suggest you try it out and see if you run into any problems. It's basically working at this time, the only thing missing is being able to specify limits in |
Thanks for your reply. |
I would recommend superseding |
I agree this is the way to go. @hadley or @yutannihilation, could I get an approval for PR #3659, so we can move forward with this? I think merging this code early in the current development cycle is a good idea, as it gives us more opportunity to catch any issues I've overlooked. |
Thanks, makes sense. I changed the issue title. |
I have a small (if it is not foolish) question: If I have several data.frames which are using different crs, how can I plot them on one plot through #3659? |
@microly Nothing fundamentally changes from before:
|
Thanks for your kind reply and sorry for this late reply! My chief concern is the regular data.frame with different crs. |
If you have different data frames with different crs you are obligated to know a bit about spatial data processing — I don’t think that is too much to ask. Basically what you describe requires the user to:
At that point, sitting down and understanding the basics of sf becomes an imperative and I don’t think it makes sense to complicate the ggplot2 API for the users who do not wish to do that |
I do not mean to change the ggplot2 API. I think a new stat may be needed to solve this problem. #3659 is great, especially it can work with geom_mark_hull(), it is wonderful! But there is a question: As a GISer, I saw a lot of ggplot2 users that know few about sf (or GIS) and just want to plot one or some of data.frames onto a map. |
If users can noly throw the data.frame into ggplot2 and tell ggplot2 the crs, then ggplot2 can draw the data onto a map. |
I saw this problem from a view of GISer, not a desinger of ggplot2, so please forgive me if my idea is wrong or even foolish. |
Users will be able to transform their data frame with one function call, see this example: Also, @paleolimbot is working on additional stats that make this easier. Not all of them need to live in ggplot2 itself: https://cran.r-project.org/web/packages/ggspatial/index.html |
I see~ |
Now that #3659 is merged, let's add this to the milestones of the next release. |
I think it's more important to mark Specifically, here are a few proposed changes for the examples provided with # modified from `geom_map()` examples, part "Better example"
library(maps)
library(ggplot2)
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
# Equivalent to crimes %>% tidyr::pivot_longer(Murder:Rape)
vars <- lapply(names(crimes)[-1], function(j) {
data.frame(state = crimes$state, variable = j, value = crimes[[j]])
})
crimes_long <- do.call("rbind", vars)
states_map <- map_data("state")
# current example, leave in
ggplot(crimes, aes(map_id = state)) +
geom_map(aes(fill = Murder), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat) # current example, remove
last_plot() + coord_map() # proposed new example
ggplot(crimes, aes(map_id = state)) +
geom_map(aes(fill = Murder), map = states_map) +
# crs = 102003 is an Albers equal area projection, see: https://epsg.io/102003
coord_sf(crs = 102003, xlim = c(-125, -70), ylim = c(25, 52)) # current example, remove
ggplot(crimes_long, aes(map_id = state)) +
geom_map(aes(fill = value), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat) +
facet_wrap( ~ variable) # proposed new example
ggplot(crimes_long, aes(map_id = state)) +
geom_map(aes(fill = value), map = states_map) +
coord_sf(crs = 102003, xlim = c(-125, -70), ylim = c(25, 52)) +
facet_wrap( ~ variable) Created on 2020-06-26 by the reprex package (v0.3.0) |
Thanks, agreed. We need to review the related documentations. The new example looks good to me! |
@clauswilke are you interested in making a conclusion on this? As far as I understand we landed on simply updating the docs? |
@thomasp85 Yes, correct, update the documentation and the examples and otherwise leave everything as is. I can add it to my todo list. |
I believe we are already in the mood of moving away from
geom_map()
asgeom_sf()
almost superseded it. But, AFAIK, this hasn't been discussed formally so far. Considering we keep developing many codes aroundgeom_sf()
, I think it's good to markgeom_map()
soft-deprecated before we face difficulties about the different behaviors between them.Here I file this issue to discuss what functionalities are missing from
geom_sf()
and its related functions, which might drive people to fall back togeom_map()
. Any thoughts?Edit: to be clear, I don't think we can remove
geom_map()
considering its wide spread usages (so I chose the word "soft-deprecated"). Still, I believe we can discourage the usage ofgeom_map()
to prevent further confusions by improvinggeom_sf()
or providing some alternatives.The text was updated successfully, but these errors were encountered: