gpt4 book ai didi

r - 您如何创建 50 个州的 map (而不仅仅是低 48 个)

转载 作者:行者123 更新时间:2023-12-04 01:25:43 24 4
gpt4 key购买 nike

你如何在 R 中制作 50 个州的 map ?

似乎人们创建的所有示例 map 都只是较低的 48

最佳答案

有很多方法可以做到这一点。就我个人而言,我发现 Google 拥有最具吸引力的 map 。我推荐 ggmap , googleVis ,和/或 RgoogleMaps .

例如:

require(googleVis)

G4 <- gvisGeoChart(CityPopularity, locationvar='City', colorvar='Popularity',
options=list(region='US', height=350,
displayMode='markers',
colorAxis="{values:[200,400,600,800],
colors:[\'red', \'pink\', \'orange',\'green']}")
)
plot(G4)

产生这个:

enter image description here

另一种方法会给您带来比 maps 更具吸引力的结果是遵循 this tutorial的方法它展示了如何将自定义 map 从 Inkscape(或等效的 Adob​​e Illustrator)导入 R 进行绘图。

你最终会得到这样的结果:

R and Inkscape

这是使用 choroplethr 的方法和 ggplot2 :
library(choroplethr)
library(ggplot2)
library(devtools)
install_github('arilamstein/choroplethrZip@v1.3.0')
library(choroplethrZip)

data(df_zip_demographics)
df_zip_demographics$value = df_zip_demographics$percent_asian

zip_map = ZipChoropleth$new(df_zip_demographics)
zip_map$ggplot_polygon = geom_polygon(aes(fill = value),
color = NA)
zip_map$set_zoom_zip(state_zoom = NULL,
county_zoom = NULL,
msa_zoom = NULL,
zip_zoom = NULL)
zip_map$title = "50 State Map for StackOverflow"
zip_map$legend = "Asians"
zip_map$set_num_colors(4)
choro = zip_map$render()
choro

data(df_pop_state)
outline = StateChoropleth$new(df_pop_state)
outline = outline$render_state_outline(tolower(state.name))

choro_with_outline = choro + outline
choro_with_outline

这给了你:

ggplot2

关于r - 您如何创建 50 个州的 map (而不仅仅是低 48 个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25530358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com