复制下面的例子我可以创建一个显示地图中点的密度的地图,但是我希望在表W上看到定量变量" dist"的密度分布,应该是什么我有这个吗?
就像这个例子 Density2d Plot using another variable for the fill (similar to geom_tile)?
但是使用stat_density2d而不是stat_summary2d。
W
lat lon dist
1 -3.844117 -32.44028 0.23
2 -3.841167 -32.39318 0.86
3 -3.808283 -32.38135 0.13
4 -3.815583 -32.39295 0.15
5 -3.844267 -32.44015 0.16
6 -3.845600 -32.44220 0.20
7 -3.866700 -32.45778 0.67
8 -3.833467 -32.39752 0.22
9 -3.871400 -32.46202 0.18
10 -3.833467 -32.39752 0.22
11 -3.833467 -32.39752 0.60
12 -3.833467 -32.39752 0.14
13 -3.833467 -32.39752 0.22
14 -3.833467 -32.39752 0.14
15 -3.833467 -32.39752 0.16
16 -3.872283 -32.42713 0.06
17 -3.849217 -32.39095 0.10
18 -3.833467 -32.39752 0.57
library(ggmap)
center <- c(-3.858331, -32.423985)
fernando.map <- get_map(location = c(center[2], center[1]), zoom = 13, color = "bw")
ggmap(fernando.map, extent = "normal", maprange=FALSE) %+% W + aes(x = lon, y = lat) +
#geom_density2d() +
stat_density2d(aes(fill = ..level.., alpha = ..level.., colour=dist),
size = 0.01, bins = 16, geom = 'polygon')