I am trying to look at insect populations over time in a given geographic location. However, I can't figure out how ggmap will take both the insect population and date factor into consideration.
Below, you can see it is plotting according to dates 0-10. However, it's not plotting the insect abundance.
My variables are adult (# insects) and the corresponding date ("num") and lat/long information. My code is as follows:
num adult lat lon
1 1 0 42.67523 -84.48507
2 1 1 42.67524 -84.48432
3 1 2 42.67473 -84.48511
4 1 0 42.67475 -84.48432
5 2 0 42.67523 -84.48507
6 2 5 42.67524 -84.48432
7 2 10 42.67473 -84.48511
8 2 2 42.67475 -84.48432
9 3 2 42.67523 -84.48507
10 3 30 42.67524 -84.48432
11 3 50 42.67473 -84.48511
12 3 5 42.67475 -84.48432
dat$cut <- cut(dat$num, breaks=seq(0,11,1), labels=sprintf("date %d",seq(0, 10, 1), seq(1,11,1)))
tunnel <- get_map(location=c(lon=-84.484652,
lat=42.675014), zoom=18, maptype='satellite')
gg <- ggmap(tunnel)
gg <- gg + stat_density2d(data=dat, aes(x=lon, y=lat, fill=..level.., alpha=..level..),
geom="polygon", size=0.01, bins=4)
gg <- gg + scale_fill_viridis()
gg <- gg + scale_fill_gradient('adult')
gg <- gg + scale_alpha(range=c(0.2, 0.4), guide=FALSE)
gg <- gg + coord_map()
gg <- gg + facet_wrap(~cut, ncol=4)
gg <- gg + labs(x=NULL, y=NULL, title="SWD Heat Map")
gg <- gg + theme_map(base_family="")
gg <- gg + theme(plot.title=element_text(face="bold", hjust=1))
gg <- gg + theme(panel.spacing.x=unit(0.5, "cm"))
gg <- gg + theme(panel.spacing.y=unit(0.5, "cm"))
gg <- gg + theme(legend.position="right")
gg <- gg + theme(strip.background=element_rect(fill="white", color="white"))
gg <- gg + theme(strip.text=element_text(face="bold", hjust=0))
gg <- gg + guides(fill = guide_colorbar(barwidth = 1.5, barheight = 10))
gg
Any help would be greatly appreciated!!