有很多方法可以做到这一点。就我个人而言,我发现谷歌拥有最有吸引力的地图。我建议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)
产生这个:
另一种方法将为您带来比以下更有吸引力的结果maps
是遵循以下方法本教程 http://www.r-bloggers.com/commandeering-a-map-from-pdf-or-eps-using-inkscape-and-r/其中演示了如何将自定义地图从 Inkscape(或等效的 Adobe Illustrator)导入到 R 中进行绘图。
你最终会得到这样的结果:
这是一种方法choroplethr
and ggplot2
:
library(choroplethr)
library(ggplot2)
library(devtools)
install_github('arilamstein/[email protected] /cdn-cgi/l/email-protection')
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
这给你: