我真的很感激
我一直在尝试使用ggmap和ggplot2组合来获取以下数据集。
我的dataframe->包含855个值的head(dt.fil(
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).
如果有人可以帮助我:(
这里有2个问题:
首先,有效的纬度从-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)
第二个问题是您的地图不够大,无法绘制这些点。要解决此问题,只需调整缩放。(我取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)