我有关于我的R脚本的问题: 如何在R中使用google map或osm tile作为背景叠加point_density? 1)这工作得很好,但不是我想要的东西:如何在R中的OSM图块上叠加点密度(ggplot2)?
library(ggmap)
map <- get_map("Vilnius", zoom = 14, source = "osm", color = "bw")
mapPoints <- ggmap(map)
p<-ggplot([email protected], aes(Y, X))
p + stat_density2d(aes(fill= ..level..), alpha =0.5, geom="polygon") + geom_point(aes(Y, X), colour="red", data = [email protected], alpha = .5)
2)如果我改用OSM瓷砖作为背景的点密度是扭曲的(可惜我不能显示说明的图像)。看来,点密度函数不能识别点的分布,并创建一个对称的叠加:
library(ggmap)
map <- get_map("Vilnius", zoom = 14, source = "osm", color = "bw")
mapPoints <- ggmap(map)
mapPoints + stat_density2d(aes(fill= ..level..), alpha =0.5, geom="polygon") + geom_point(aes(Y, X), colour="red", data = [email protected], alpha = .5)
下面是一些样本数据:
OID_ Y X
0 25.29315500000 54.68288700000
0 25.29375600000 54.68260200000
0 25.28416600000 54.68472200000
0 25.29776900000 54.68051900000
0 25.29549400000 54.68064800000
0 25.25535200000 54.67742600000
0 25.29541800000 54.68429700000
0 25.29751100000 54.68445600000
0 25.29541800000 54.68429700000
0 25.29541800000 54.68429700000
0 25.29751100000 54.68445600000
0 25.29751100000 54.68445600000
0 25.29751100000 54.68445600000
0 25.29751100000 54.68445600000
0 25.28865900000 54.68074300000
0 25.28943200000 54.67457100000
0 25.29133200000 54.68690000000
0 25.29176000000 54.68873800000
0 25.28049400000 54.67952800000
什么,我做错了什么?
感谢您的任何帮助
你能提供数据集'geotag @ data'(或它来自的空间数据框)吗?这只是一个猜测,但失真可能在第一个图中。 'ggmap(...)'将纵横比设置为1:1以避免失真*。你不会在第二段中做到这一点。尝试在最后一条语句中添加'+ coord_fixed()'。 – jlhoward