您如何创建50个州的地图(而不是仅48个州的地图) [英] How do you create a 50 state map (instead of just lower-48)

查看:71
本文介绍了您如何创建50个州的地图(而不是仅48个州的地图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在R中制作50个州的地图?

How do you make a 50 state map in R?

人们创建的所有示例地图似乎都只是下面的48张

It seems like all the example maps people have created are just of the lower 48

推荐答案

有很多方法可以做到这一点.我个人认为Google具有最吸引人的地图.我建议ggmapgoogleVis和/或RgoogleMaps.

There are lots of ways that you can do this. Personally, I find Google to have the most attractive maps. I recommend ggmap, googleVis, and/or 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)

产生这个:

另一种比maps更具吸引力的方法是采用

Another approach that will give you a more attractive result than maps is to follow the approach of this tutorial which shows how to import custom maps from Inkscape (or, equivalently, Adobe Illustrator) into R for plotting.

您最终会得到这样的东西:

You'll end up with something like this:

这是使用choroplethrggplot2的一种方法:

Here's a way to it with choroplethr and 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

为您提供:

这篇关于您如何创建50个州的地图(而不是仅48个州的地图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆