我使用library(choroplethr)
一些市場分析和我有讓我county_choropleth
,要麼覆蓋其上ggmap()
頂部或在我的代碼使用reference_map=TRUE
一些問題。我想要做的就是帶上我的縣長,並將狀態州際公路和州/圈繪製成圓圈/半徑。道路和半徑的圓,在choroplethr,ggmap,或GGPLOT2
我現在有是這樣的:
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())
從這裏,我想這樣做是覆蓋在我的地圖頂部在愛荷華州的主要州際公路,也創造了一些半徑的圓顯示在英里某些城市的距離。我想它從這個地圖需要的元素和理想它們納入我的choroplethr地圖,因爲,在我看來,它看起來比這個例子更清潔了很多:
我用這個代碼來檢索第二張圖:
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")
我與在choroplethr
庫使用reference_map=TRUE
主要問題是,它呈灰色標籤,道路等,當我把我的county_choropleth在它的上面。
那麼,是否有一個簡單的解決方法,包括在地圖上的道路和繪圖圈,還是我需要放棄使用choroplethr
並移動到ggmap,ggplot2或其他?我也可以在他們的網站上找到道路的愛荷華州DOT形狀文件,所以這是一個包含的選項,但我不知道在繪圖和閱讀R時如何使用主要州際公路/高速公路。
預先感謝您的任何和所有幫助,請讓我知道,如果你有需要,爲了回答任何澄清的問題幫幫我!
我沒有給你一個答案,但我認爲,傳單會允許你這樣做所有你想要的。輸出是一個html文檔,但你可以拍一張快照 – MLavoie
因此,看單張,我已經能夠拿出[this](https://i.gyazo.com/d4ab07e7901a6081898b9d1ae28f8d0f.png)到目前爲止。那麼我的問題就變成了如何按照上面所做的方式去貼上這些縣的標籤?我是否需要使用形狀文件,還是可以像以前一樣使用縣FIPS?順便說一下,傳單是一個很好的工具,我不能感謝你讓我接受它! – medavis6
不錯!嘗試添加一個彈出窗口https://rstudio.github.io/leaflet/shapes.html – MLavoie