我必须在 map 上绘制一些点。我想用qmplot
,因为它看起来简单有效。
我关注了this tutorial ,但我无法让它工作:
# Libraries
install.packages("maps")
install.packages("ggmap")
library(maps)
library(ggmap)
# Loading European map:
map <- get_map(location = 'Europe', zoom = 4)
ggmap(map)
# Madrid coordinates
df <- data.frame(lon=c(-3.757324), lat=c(40.441721))
# Plotting the point
qmplot(df$lon, df$lat)
qmplot(df$lon, df$lat, data = df)
我收到这个错误:
Error in `[.data.frame`(data, , deparse(substitute(x))) :
undefined columns selected
最佳答案
如果您想在第一步获得的欧洲 map 上绘制您的点,您可以改为这样做:
# Libraries
library(maps)
library(ggmap)
# Loading European map:
map <- get_map(location = 'Europe', zoom = 4)
# Madrid coordinates
df <- data.frame(lon=c(-3.757324), lat=c(40.441721))
ggmap(map) + geom_point(data = df, aes(x = lon, y = lat))
关于r - 带有 qmplot 的 map 中的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33597821/