Roads and radius Kroogi in choroplethr, ggmap or ggplot2

I use library(choroplethr) for some market analysis, and I have some questions about creating my county_choropleth and either overlaying it on top of ggmap() or using reference_map=TRUE in my code. What I'm trying to do is take my count's horolept and place state interstate / highways and draw circles / radii on top of it.

I currently have:

 library(choroplethr) data <- Data.frame(County.FIPS = c(19153,19163,19153,19153,19153,19153,19153,19113,19007,19169), Score=c(812.6,769.5,757.9,757.2,722.6,712.4,69727,690.2,64539,642.5) county <-aggregate(data$Score~data$County.FIPS,data=data,sum) colnames(county) <- c("region", "value") mp <- county_choropleth(county, state_zoom=c("iowa"), num_colors = 1) + theme(legend.position="none")+ scale_fill_gradient2("Score", high = "dark green", low = "red", na.value = "grey90", breaks = pretty(county$value, n = 10), label = scales::dollar_format()) 

... which gives me this plot. enter image description here

From here, I would like to overlay the major states in Iowa on top of my map, as well as create radius circles to show the distance from some cities in miles. I would like him to take elements from this map and ideally include them in my choroplethr map, because, in my opinion, it looks much cleaner than in this example: <img src = "https: //i.stack. imgur.com/mphLs.png "alt =" enter a description of the image here ">

I used this code to extract the second card:

 library(ggmap) test<-get_map(location = c(lon=-93.57217,lat=41.67269), maptype="roadmap",source="google",zoom=7,scale="auto") yup <- data.frame(lon=c(-93.57217,-95.87509), lat=c(41.67269,41.23238),score=c(1,1)) ggmap(test) + stat_density2d(aes(x = lon, y = lat, fill = score,alpha=score), size = 2, bins = 2, data = yup, geom = "polygon") + theme(legend.position="none") 

My main problem with using reference_map=TRUE in the choroplethr library is that it is highlighted with shortcuts, roads, etc. when I put my county_choropleth on top of it. eg, enter image description here

So, is there an easy way to turn roads and draw circles on the map, or do I need to stop using choroplethr and go to ggmap, ggplot2 or something else? I was also able to find Iowa DOT shapefiles for roads on my website, so this is an option, but I don't know how to specifically ask him to use the main interstate / highway when building and reading in R.

Here is my β€œperfect” MS Paint solution for this problem: enter image description here

Thanks in advance for any help and please let me know if you have any clarifications that need to be answered to help!

+5
source share
1 answer

For those who stumble upon this later. I managed to achieve what I was hoping to do by changing the libraries to leaflet and tigris .

enter image description here

I plan to make the final settings for personal use, but the code is used here:

 library(tigris) library(leaflet) data <- data.frame(County.FIPS = c(19153,19163,19153,19153,19153,19153,19153,19113,19007,19169), Score=c(812.6,769.5,757.9,757.2,722.6,712.4,69727,690.2,64539,642.5)) county <-aggregate(data$Score~data$County.FIPS,data=data,sum) colnames(county) <- c("GEOID", "Score") IA_counties <- counties(state="IA", cb=TRUE, resolution ="20m") IA_merged <- geo_join(IA_counties,county,"GEOID", "GEOID") pal <- colorQuantile("Greens",NULL,n=3) popup <- paste0("Profitability: ", as.character(IA_merged$Score)) yup2 <- data.frame(lon=c(-93.57217,-95.93779),lat=c(41.67269,41.25861),score=c(1,1)) leaflet() %>% addProviderTiles("Esri.WorldStreetMap") %>% addLegend(pal = pal, values = IA_merged$Score, position = "bottomright", title = "County Profitablity: ") %>% addCircles(lng=yup2$lon, lat=yup2$lat,weight=1,fillOpacity=0.05,color="red", radius = 96560) %>% addCircles(lng=yup2$lon, lat=yup2$lat,weight=1,fillOpacity=0.025,color="blue", radius = 193121) %>% addPolygons(data = IA_counties, fillColor = ~pal(IA_merged$Score), fillOpacity = 0.15, weight = 0.2, popup = popup) 
+2
source

Source: https://habr.com/ru/post/1237658/


All Articles