copying the example below I could create a map that shows the density of points in the map, but I would like to see a density distribution of the quantitative variable "dist", on table W, what should I do to have that?
As this example Density2d Plot using another variable for the fill (similar to geom_tile)?
but with stat_density2d instead of 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')