【发布时间】:2021-03-17 00:04:30
【问题描述】:
我在数据框中有空间坐标,其中每一行(经度、纬度)对应于我正在关注的事件的发生。我试图映射这些数据,但我不想使用点,而是想创建一个网格,其单元格的分辨率为 5 海里(~ 0.083333),并计算每个单元格的事件发生次数并绘制它。
这是我在一些资源的帮助下编写的代码。但它看起来不像我预期的那样。你能弄清楚我做错了什么吗?我附上了原始位置和我得到的结果地图。 这是data的链接。
re_pi = read.csv(file = "~/Desktop/Events.csv")
gridx <- seq(from=-19,to=-10,by=0.083333)
gridy <- seq(from=20,to=29,by=0.083333)
xcell <- unlist(lapply(re_pi$LON,function(x) min(which(gridx>x))))
ycell <- unlist(lapply(re_pi$LAT,function(y) min(which(gridy>y))))
re_pi$cell <- (length(gridx) - 1) * ycell + xcell
rr = re_pi %>%
group_by(cell)%>%
summarise(Lat = mean(LAT),Lon = mean(LON),Freq = length(cell))
my_theme <- theme_bw() + theme(panel.ontop=TRUE, panel.background=element_blank())
my_cols <- scale_color_distiller(palette='Spectral')
my_fill <- scale_fill_distiller(palette='Spectral')
ggplot(rr, aes(y=Lat, x=Lon, fill=Effort)) + geom_tile(width=1.2, height=1.2) +
borders('world', xlim=range(rr$Lon), ylim=range(rr$Lat), colour='black') + my_theme + my_fill +
coord_quickmap(xlim=range(rr$Lon), ylim=range(rr$Lat))
【问题讨论】:
-
你能提供你的 shapefile 吗?
-
我没有 shapefile,也没有使用 shapefile。