2012-02-27 3 views
5

좋은 하루 모두,ggplot2 및지도 : geom_point 및 annotation_raster 위치 불일치

내가 성공적으로 ggmap를 사용하여 Google에서 래스터를 검색 할 수 있습니다 아래의 코드를 사용하여이 위에 빨간 점 같은 annotation_rasterggplot2을 사용하고 플롯 사이트 지방 음모 래스터 레이어의 작의에서 위치는 꽤 일치하지 않습니다 (그들은 해안선을 따라야합니다). Google 어스에 KML 파일로 데이터를 업로드 할 때 위치를 지정하기 때문에 내 사이트의 위치가 정확하다는 것을 알고 있습니다.

제안 사항에 감사드립니다.

이 코드는 그대로 실행됩니다 ...의 개발 버전이 필요하며 github에서 사용할 수 있습니다.

# install.packages("devtools") 
library(devtools) 
install_github("ggplot2") 

를하고 코드 : 설치하려면

library(ggplot2) 
library(ggmap) 
library(grDevices) 
theme_set(theme_bw()) 

# Some coordinates of points to plot: 
siteLat = c(-22.94414, -22.67119, -29.25241, -30.31181, -32.80670, -33.01054, -32.75833, -  33.36068, -31.81708, -32.09185, -32.31667, -34.13667, -34.05016, -33.91847, -34.13525, -34.12811, -34.10399, -34.16342, -34.41459, -34.58786, -34.83353, -34.37150, -34.40278, -34.17091, -34.08565, -34.04896, -33.98066, -34.02448, -34.20667, -34.05889, -33.97362, -33.99125, -33.28611, -33.02407, -33.01798, -32.99316, -31.09704, -31.05000, -30.91622, -30.70735, -30.28722, -30.27389, -29.86476, -29.54501, -29.49660, -29.28056, -28.80467, -27.42472) 
siteLon = c(14.50175, 14.52134, 16.86710, 17.26951, 17.88522, 17.95063, 18.02778, 18.15731, 18.23065, 18.30262, 18.32222, 18.32674, 18.34971, 18.38217, 18.43592, 18.45077, 18.48364, 18.85908, 19.25493, 19.33971, 20.00439, 21.43518, 21.73972, 22.12749, 23.05532, 23.37925, 23.64567, 23.89933, 24.77944, 25.58889, 25.64724, 25.67788, 27.48889, 27.91626, 27.92182, 27.95036, 30.18395, 30.21666, 30.32982, 30.48474, 30.76026, 30.83556, 31.04479, 31.21662, 31.24665, 31.44403, 32.07567, 32.73333) 
siteName = c(seq(1:length(siteLon))) 
sites <- as.data.frame(cbind(siteLat, siteLon, siteName)) 

# specify raster's approximate coordinates: 
lats = c(-35, -20) 
lons = c(10, 35) 

SAMap <- GetMap.bbox(lons, lats, maptype = "satellite") 

# extract "real" coords of raster: 
lonr <- c(SAMap$BBOX$ll[2], SAMap$BBOX$ur[2]) 
latr <- c(SAMap$BBOX$ll[1], SAMap$BBOX$ur[1]) 

# extract raster fill data: 
h_raster <- as.raster(SAMap$myTile) 

# plot using annotation_raster: 
g <- ggplot(sites, aes(siteLon, siteLat)) 
g + annotation_raster(h_raster, lonr[1], lonr[2], latr[1], latr[2]) + 
    geom_point(aes(x = siteLon, y = siteLat), colour = "red", data = sites) + 
    scale_x_continuous(limits = lonr) + 
    scale_y_continuous(limits = latr) 

은 (내가 여기에 새로운 오전으로 죄송합니다, 제가 이미지를 게시 할 수 없습니다).

+0

을이 내 컴퓨터에서 실행되지 않습니다. 나는 또한 당신이'library (raster)'를 포함 할 필요가 있다고 생각한다. 그렇다면 'annotation_raster'를 찾을 수 없습니다. 어떤 패키지 (및 버전)에 있습니까? – Andrie

+0

실험적인'ggplot2' 버전이 필요하다고 생각합니다. 설치 방법은 https://github.com/hadley/ggplot2를 참조하십시오. –

+0

'as.raster()'가'라이브러리 (grDevices)'에 있다고 생각합니다. 'annotation_raster'는'ggplot2' 버전 0.9.0에 있습니다. 상단의 코드를 업데이트합니다. –

답변

관련 문제