r - 带有 qmplot 的 map 中的点

标签 r google-maps plot point

我必须在 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/

相关文章:

javascript - 谷歌地图绘制行驶距离折线

python - 在 python 中的绘图中的自定义线之间放置图像

r - 为巨大的数据表元素赋值太慢

r - 使用 R 中的 apply 系列将 2 列数据框的每一行传递给我创建的函数?

java - 当我平移 map 时,Google map 叠加层不会移动

javascript - 使用 Google Maps API 对 LatLong 进行地理编码返回未定义

r - 在条形图中添加每组的观察数(ggplot2)

r - 按组合划分的出现频率(2 × 2)

python - 如何在不添加 "ticks"的情况下从下到上移动标签

r - curve() 在第一个示例中有效,但在第二个示例中无效,但它们看起来相同。为什么?