尝试在R中绘制坐标时出错

时间:2017-04-05 13:44:36

标签: r ggplot2 ggmap

我想将数据集中的坐标绘制到地图上,我使用了从Here找到的代码。我的代码看起来像这样:

# creating a sample data.frame with your lat/lon points
lon <- c(known_long_lat$takeoff.longitude)
lat <- c(known_long_lat$takeoff.latitude)
df <- as.data.frame(cbind(lon,lat))

# getting the map
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 4, maptype = "satellite", scale = 2)

# plotting the map with some points on it
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), 
size = 5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)`

当我运行此代码时,我收到此错误:

  

if(lon&lt; -180 || lon&gt; 180){:     缺少需要TRUE / FALSE的值   另外:警告信息:   1:在mean.default(df $ lon)中:     参数不是数字或逻辑:返回NA   2:在mean.default(df $ lat)中:     参数不是数字或逻辑:返回NA

我想也许是因为我在纬度和经度列中有非数字数据,但似乎没有。

0 个答案:

没有答案
相关问题