Good evening,
I am trying to overlay multiple densities over a single map and i cannot figure out how to 1) color the densities (not the contours) according to group variable. 2) how to capture the minimum range.
What i would like to see are colorful densities varying in transparency all over the map. However only the contour lines change colors. Furthermore, due to the large amount of data in some areas, the lowest levels are not highlighted at all. I as wondering if there is a way to break up the bins as something like log(count) instead of count. I suppose i could do the 2nd part manually. But I have no idea how to get the density fill color to work. My coding attempts are provided below. I really appreciate your help.
ggmap(map, extent = "normal", maprange=FALSE) +
stat_density2d(aes(x = longitude, y = latitude, color=as.factor(cluster), alpha=..level..), data=test1, size=1, contour=TRUE)
t2 <- ggmap(map, extent = "normal", maprange=FALSE) %+% test1 +
aes(x = longitude, y = latitude, color=as.factor(cluster), fille= as.factor(cluster)) +
geom_density2d() +
stat_density2d(aes(fill =as.factor(cluster), alpha = ..level..), size = 0.001, bins = 200, geom = 'polygon') +
#scale_fill_descrete(low = "green", high = "red") +
scale_alpha(range = c(0.000, 0.3), guide = FALSE) +
coord_map(projection="mercator", xlim=c(attr(map, "bb")$ll.lon,
attr(map, "bb")$ur.lon), ylim=c(attr(map, "bb")$ll.lat, attr(map, "bb")$ur.lat))
here is the example of data i'm using. I can't share the whole file.
longitude latitude timestamp mon wday time cluster
1 118.2892 30.15523 1/1/12 19:16 0 0 979 2
2 111.7409 30.78840 1/1/12 9:26 0 0 1569 3
3 111.7409 30.78840 1/1/12 9:23 0 0 1389 1
4 111.7410 30.76408 1/1/12 9:22 0 0 1329 2
5 111.7936 30.81234 1/1/12 9:21 0 0 1269 2
6 111.7908 30.81940 1/1/12 9:20 0 0 1209 4
Apparently i can't post my image due to lack of reputation, but it's not very pretty. and this is the picture i get. There is actually data all over the map (and more than two groups but that's not important). But the only way i can increase the coverage is by increasing the number of bins.