v <- 2^(7:17)
min_lon <- 6.164780
max_lon <- 15.744857
min_lat <- 47.228296
max_lat <- 54.426407
center_lon <- (min_lon + max_lon)/2
center_lat <- (min_lat + max_lat)/2
df <- data.frame(id = 1:sum(v))
df$T <- rep(paste("T", v, sep="_"), v)
df$lon <- runif(sum(v),min_lon, max_lon)
df$lat <- runif(sum(v),min_lat,max_lat)
Making a heatmap with transparency=..level..
gg_heatmap <- function(T){
g <- ggmap(get_map(location=c(lat=center_lat, lon=center_lon), zoom=6, maptype="roadmap", source="google"))
g <- g + scale_fill_gradientn(colours=rev(rainbow(100, start=0, end=0.75)))
g <- g + stat_density2d(data=df[df$T == "T_1024",], aes(x = lon, y = lat,fill = ..level..,transparency=..level..),
size=1, bins=100, geom = 'polygon')
print(g)
}
system.time(gg_heatmap("T_1024"))
Making a heatmap by setting alpha = .05
gg_heatmap <- function(T){
g <- ggmap(get_map(location=c(lat=center_lat, lon=center_lon), zoom=6, maptype="roadmap", source="google"))
g <- g + scale_fill_gradientn(colours=rev(rainbow(100, start=0, end=0.75)))
g <- g + stat_density2d(data=df[df$T == "T_1024",], aes(x = lon, y = lat,fill = ..level..), alpha=.05,
size=1, bins=100, geom = 'polygon')
print(g)
}
system.time(gg_heatmap("T_1024"))
Both results aren't satisfying. I would prefer to see something like the following heatmap made with QlikView and using the same data set "T_1024".
There are three aspects I prefer about the QV-version:
- The transparency allows to still see the map underneath ...
- ... while the colors are still expressive and not pale
- The coloring allows to indentify more details
I tried to tackle (1) by experimenting with different ways of setting the alpha level statically as well as relative to ..level.. Yet I could not get good results. The transparency is never really good and if I see the map the colors too pale.
(3) I thought I could influence by setting a high bin value.
Any ideas how to optimize the heatmap rendering or at least aspects of it?
transparency
a valid argument tostat_density2d(...)
?? Why aren't you usingalpha=..level..
? – Cytolysis