this을 참조로 사용하면 더 낮은 48 개의지도를 플롯하고 상태 간 흐름을 시각화하기 위해 레이어를 추가하려고합니다. 나는이 문제를 디버깅하려고ggplot 맵에 지리 공간 연결을 추가하는 방법은 무엇입니까?
p
Error in eval(expr, envir, enclos) : object 'lon' not found
플롯을 인쇄하려고이
p + geom_line(data = list_lines[[1]], aes(x = lon, y = lat), color = '#FFFFFF')
하지만 두 번째의 또 다른 레이어를 추가를 작동 발견했을 때 여기
library(ggplot2)
library(maps)
library(geosphere) # to inter-polate a given pair of (lat,long) on the globe
# load map data for the US
all_states <- map_data("state")
# plot state map
p <- ggplot() + geom_polygon(data=all_states,
aes(x=long, y=lat, group = group),
colour="white", fill="grey10")
# sample origin - destination lat,long pairs
geo <- structure(list(orig_lat = c(36.17, 36.17, 36.17),
orig_lon = c(-119.7462, -119.7462, -119.7462), dest_lat = c(33.7712, 36.17, 39.0646),
dest_lon = c(-111.3877, -119.7462, -105.3272)), .Names = c("orig_lat",
"orig_lon", "dest_lat", "dest_lon"), row.names = c(NA, 3L), class = "data.frame")
#> geo
# orig_lat orig_lon dest_lat dest_lon
#1 36.17 -119.7462 33.7712 -111.3877
#2 36.17 -119.7462 36.1700 -119.7462
#3 36.17 -119.7462 39.0646 -105.3272
# list to hold a dataframe of interpolated points for each origin-destination pair
list_lines <- list()
# use the geosphere package's gcIntermediate function to generate 50 interpolated
# points for each origin-destination pair
for (i in 1:3) {
inter <- as.data.frame(gcIntermediate(c(geo[i,]$orig_lon, geo[i,]$orig_lat),
c(geo[i,]$dest_lon, geo[i,]$dest_lat),
n=50, addStartEnd=TRUE))
list_lines[i] <- list(inter)
p <- p + geom_line(data = list_lines[[i]], aes(x = lon, y = lat), color = '#FFFFFF')
}
p
내가 무엇을 얻을 list 엘리먼트는 그것을 깨뜨린 다. 그러나 그것은 내가 R과 ggplot에 대한 나의 제한된 지식으로 얻을 수있는 한도 내이다.
! 그게 문제를 고쳤어, 고마워! – JConnor