[R] Recommended ways to draw US Census map on Open Street Map base map?
bgunter@4567 @end|ng |rom gm@||@com
Tue Jun 6 21:17:58 CEST 2023
As you are using Rstudio stuff(ggplot, tidyverse,etc.), you might try the
RStudio support site here <https://community.rstudio.com/> (note that they
have rebranded under the banner "posit.co").
However, I would have also thought the R-sig-geo list was the best place to
look for such help.
On Tue, Jun 6, 2023 at 11:38 AM Kevin Zembower via R-help <
r-help using r-project.org> wrote:
> Hello, all,
> I asked a version of this question on the R-sig-geo list, but didn't get
> any response. I'm asking here in the hopes of a wider audience.
> I'm trying to draw US Census map data, fetched with tigris, on top of a
> base map fetched by the package OpenStreetMap. I'm hoping for the most
> straight-forward solution. I made significant progress with leaflet(),
> but didn't need the interactivity of the map. I just need a 2D, static
> map that I can print and include in a document.
> Here's some of what I've tried so far:
> options(tigris_use_cache = TRUE)
> ## Get an Open Street Map:
> rw_map <- openmap(nw, se,
> type = "osm",
> mergeTiles = TRUE) %>%
> openproj(projection = "+proj=longlat +ellps=WGS84 +datum=WGS84
> ## Get an example census map:
> rw_tract <- tracts(state = "MD",
> county = "Baltimore city",
> year = "2020") %>%
> filter(NAME == "2711.01")
> ## This works:
> ## So does this:
> ## These don't:
> autoplot.OpenStreetMap(rw_map) +
> ggplot(map_data(rw_map), aes(long, lat))
> ggplot(aes(x="long", y="lat")) +
> I think my problem in part is failing to fully understand the formats of
> the rw_map and rw_tract containers. rw_tract says it's a simple feature
> collection, but rw_map just gives me lists of the data.
> Can anyone help nudge me along in getting my rw_tract to be drawn on my
> rw_map? Any advice or guidance on putting together map data from
> different sources?
> And an over-arching question: Is moving in this direction, with ggplot2,
> the way you would recommend accomplishing this task? Is there a simpler,
> more straight-forward way of doing this?
> Thanks in advance for your help and efforts.
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help