绘制坐标ggmap的问题

卡姆兰·马马扎达

我一直在尝试使用ggmap和ggplot2组合获取以下数据集进行映射。

我的数据框-> head(dt.fil)包含855个值

        lat     lon        airline
1  -73.9930 40.7480 Virgin America
2  -71.0200 42.3610 Virgin America
3 -118.4062 33.9454 Virgin America
4 -118.4041 33.9421 Virgin America
5  -96.9322 33.2145 US Airways
6 -118.3859 34.0220 United

我的代码如下

map_airlines <- get_map(location = c(lon = mean(dt.fil$lon),
                                     lat = mean(dt.fil$lat)), zoom = 5,
                        maptype = "satellite", scale = 2)

# visualze the tweet locations
ggmap(map_airlines) +
  geom_point(data=dt.fil, aes(x=lon, y=lat, fill='red',
                              alpha=0.6, colour=airline)) +
  guides(fill=FALSE, alpha=FALSE)

我收到以下错误

Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
5: Removed 835 rows containing missing values (geom_point).

如果有人可以帮助我,我将非常感激:)

DCZ

这里有两个问题:

  1. 首先,有效纬度从-90到+90,而有效经度从-180到+180。鉴于您的纬度不在此范围内,我想您已将它们切换了。因此,在本示例的其余部分中,我将纬度更改为经度,并将经度更改为纬度。(看到您正在与美国航空公司合作,并且数据点都位于美国,这似乎是合理的)。

    lon <- c(-73.9930 , -71.0200 , -118.4062 , -118.4041, -96.9322 , -118.3859 )
    lat <- c(40.7480,  42.3610 , 33.9454 , 33.9421 , 33.2145 , 34.0220 )
    airline <- c("Virgin America", "Virgin America", "Virgin America", "Virgin America", "US Airways", "United")
    dt.fil <- data.frame(lat, lon, airline)
    
  2. 第二个问题是您的地图不够大,无法绘制点。要解决此问题,只需调整缩放比例即可。(我花了3个而不是5个,只需对其进行调整,直到所有数据点都适合为止)。

    map_airlines <- get_map(location = c(lon = mean(dt.fil$lon),
                                 lat = mean(dt.fil$lat)),
                    zoom = 3,
                    maptype = "satellite", scale = 2)
    
    #visualze the tweet locations
    ggmap(map_airlines) +
    geom_point(data=dt.fil, aes(x=lon, y=lat, colour=airline), fill='red',
         alpha=0.6) +
    guides(fill=FALSE, alpha=FALSE)
    

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章