我有關於我的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