R ggplot2/ggmap:以点的形式绘制同心圆

6
我正在尝试绘制一些信息,以在地图上显示整个人口和该人口的某个子集按位置划分的情况。我看过使用同心圆或3D倒置锥体来传达此信息的数据可视化。我只是不知道如何在ggplot / ggmap中实现它。
这里是在Paint中手绘的免费版本,显示了我想要做的大致想法: enter image description here 这是一个示例的粗略数据:
> dput(df1)
structure(list(zip = c("00210", "00653", "00952", "02571", "04211", 
"05286", "06478", "07839", "10090", "11559"), city = c("Portsmouth", 
"Guanica", "Sabana Seca", "Wareham", "Auburn", "Craftsbury", 
"Oxford", "Greendell", "New York", "Lawrence"), state = c("NH", 
"PR", "PR", "MA", "ME", "VT", "CT", "NJ", "NY", "NY"), latitude = c(43.005895, 
17.992112, 18.429218, 41.751554, 44.197009, 44.627698, 41.428163, 
41.12831, 40.780751, 40.61579), longitude = c(-71.013202, -66.90097, 
-66.18014, -70.71059, -70.239485, -72.434398, -73.12729, -74.678956, 
-73.977182, -73.73126), timezone = c(-5L, -4L, -4L, -5L, -5L, 
-5L, -5L, -5L, -5L, -5L), dst = c(TRUE, FALSE, FALSE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE), totalPop = c(43177, 37224, 37168, 
15492, 1614, 88802, 2587, 80043, 78580, 87461), subPop = c(42705, 
36926, 27556, 10827, 774, 39060, 1542, 21304, 53438, 2896)), .Names = c("zip", 
"city", "state", "latitude", "longitude", "timezone", "dst", 
"totalPop", "subPop"), row.names = c(1L, 50L, 200L, 900L, 1500L, 
2000L, 2500L, 3000L, 3500L, 4000L), class = "data.frame")

任何建议吗?
1个回答

10
基本思路是为两个人群使用单独的几何图形,确保较小的人群在较大的人群之后绘制,这样它的层就在顶部:
library(ggplot2) # using version 0.9.2.1
library(maps)

# load us map data
all_states <- map_data("state")

# start a ggplot. it won't plot til we type p
p <- ggplot()  

# add U.S. states outlines to ggplot
p <- p + geom_polygon(data=all_states, aes(x=long, y=lat, group = group),
     colour="grey", fill="white" )

# add total Population
p <- p + geom_point(data=df1, aes(x=longitude, y=latitude, size = totalPop), 
     colour="#b5e521")

# add sub Population as separate layer with smaller points at same long,lat
p <- p + geom_point(data=df1, aes(x=longitude, y=latitude, size = subPop), 
     colour="#00a3e8")

# change name of legend to generic word "Population"
p <- p + guides(size=guide_legend(title="Population"))

# display plot
p 

enter image description here

从地图上可以看出,您的数据包括非连续的美国地点,这种情况下,您可能需要不同的底层地图数据。来自ggmap包的get_map()函数提供了几个选项:

require(ggmap)
require(mapproj)
map <- get_map(location = 'united states', zoom = 3, maptype = "terrain", 
       source = "google")
p <- ggmap(map)

接下来,您需要将总人口和子人口的geom_point()图层相加,并像之前一样进行显示。


这个链接使用类似的方法在各州之间创建热力图 http://www.dataincolour.com/2011/07/maps-with-ggplot2/ - chandler

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接