0

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')
Community
  • 1
  • 1
user1265067
  • 867
  • 1
  • 10
  • 26
  • Are you after something like this? `ggmap(fernando.map) + stat_density2d(data = W, aes(x = lon, y = lat, fill = ..level.., alpha = ..level..), size = 0.01, bins = 16, geom = "polygon")` – jazzurro Jan 22 '15 at 15:40
  • kind of, but if I do this way, with W$dist <- 0 it gives the plot, the density is representing the distribution of points not the values of variable dist in two dimensions, do you understand what I want? – user1265067 Jan 22 '15 at 15:44
  • Ah I think I know what you mean now. – jazzurro Jan 22 '15 at 15:47

0 Answers0