我试图在特定的地理位置观察昆虫种群。但是,我无法弄清楚ggmap如何考虑昆虫种群和日期因素。
下面,您可以看到它根据日期0-10进行绘图。然而,它并没有绘制昆虫的丰富程度。
我的变量是成人(#昆虫)和相应的日期(“num”)和纬度/经度信息。我的代码如下:
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
任何帮助将不胜感激!!