2013-10-05 3 views
4

ggplot2 패키지의 fortify 함수를 사용하여 공간 객체를 data.frame으로 변환하려고합니다. 하지만 오류가 발생합니다. 나는 유타 개체를 변환 할 때, 그러나ggplot2의 함수 강화 오류

> str(utah) 
     [email protected] data  :'data.frame': 10 obs. of 8 variables: 
     .. ..$ AREA  : num [1:10] 1.42e+11 1.33e+11 3.10e+11 4.47e+10 1.26e+11 ... 
     .. ..$ PERIMETER : num [1:10] 4211300 3689180 4412500 2722190 3388270 ... 
     .. ..$ USECO_ : int [1:10] 164 170 204 208 247 367 373 386 409 411 
     .. ..$ USECO_ID : int [1:10] 163 216 201 206 245 366 372 385 408 410 
     .. ..$ ECO  : Factor w/ 7 levels "13","14","18",..: 7 3 1 4 5 6 2 4 4 6 
     .. ..$ LEVEL3 : int [1:10] 80 18 13 19 20 21 14 19 19 21 
     .. ..$ LEVEL3_NAM: Factor w/ 7 levels "Central Basin and Range",..: 4 7 1 6 2 5 3 6 6 5 
     .. ..$ id  : chr [1:10] "0" "1" "2" "3" ... 
     ... 
     ... 

:

require("rgdal") 
require("maptools") 
require("ggplot2") 
require("plyr") 
utah = readOGR(dsn="/path/to/shapefile", layer="eco_l3_ut") 
    OGR data source with driver: ESRI Shapefile 
    Source: ".", layer: "eco_l3_ut" 
    with 10 features and 7 fields 
    Feature type: wkbPolygon with 2 dimensions 
[email protected]$id = rownames([email protected]) 

모든 확인을 작동하는 것 같다 예를 들어, Hadley Wickhan's plotting polygon shapefiles example에 사용되는 동일한 코드 다음, 나는 명령의 다음 줄을 입력

> utah.points = fortify(utah, region="id") 
    Error in UseMethod("fortify") : no applicable method for 'fortify' applied to an object of class "c('SpatialPolygonsDataFrame', 'SpatialPolygons', 'Spatial')" 

내가 시도 다른 모든 공간 객체에 대해 같은 오류가 점점 오전 : 함수를 사용하면 packcage의 ggplot2에서 강화, 나는 다음과 같은 오류가 발생합니다 강화를 사용하여 변환; (R의 버전 3.0.2로 업그레이드하기 전에) 과거에 괜찮은 코드를 사용할 때조차도.

Intel Core i7 및 16GB RAM이 장착 된 Mac에서 R 버전 3.0.2를 실행하고 있습니다.

답변

0

이 문제는 .Rprofile 파일과 관련이 있음을 알았습니다. 이것은 내가 그 파일에있는 것입니다 :

options(repos="http://cran.stat.ucla.edu") 
utils::update.packages(ask=FALSE) 
pkgs <- getOption("defaultPackages") 
options(defaultPackages = c(pkgs,"ggplot2","arm", "Zelig","stringr", "plyr", "reshape2", "MatchIt", "ISLR", "rgdal")) 

.Rprofile에서 부하를 ggplot2 때마다, 내가 위에서 내 질문에서 언급 한 오류가 발생합니다. .Rprofile 옵션에서 ggplot2를 꺼낼 때마다 오류가 발생하지 않습니다.

0

shapefile을 다운로드하고 코드를 시도했습니다. 그것 (또는 오히려 forfify) 내 설치에 잘 작동하는 것처럼 보였다. 주 패키지를 다시 설치하고 재부팅하고 다시 시도하십시오.

> utah.points = fortify(utah, region="id") 
Loading required package: rgeos 
rgeos version: 0.3-1, (SVN revision 413M) 
GEOS runtime version: 3.3.8-CAPI-1.7.8 
Polygon checking: TRUE 

> head(utah.points) 
     long  lat order hole piece group id 
1 -1405382 2224519  1 FALSE  1 0.1 0 
2 -1406958 2222744  2 FALSE  1 0.1 0 
3 -1408174 2221195  3 FALSE  1 0.1 0 
4 -1409680 2220162  4 FALSE  1 0.1 0 
5 -1411068 2219579  5 FALSE  1 0.1 0 
6 -1412780 2219001  6 FALSE  1 0.1 0 
> tail(utah.points) 
      long  lat order hole piece group id 
19615 -1172872 1741373 19615 FALSE  1 9.1 9 
19616 -1172522 1740139 19616 FALSE  1 9.1 9 
19617 -1172366 1739158 19617 FALSE  1 9.1 9 
19618 -1172124 1737840 19618 FALSE  1 9.1 9 
19619 -1171788 1737281 19619 FALSE  1 9.1 9 
19620 -1171309 1736884 19620 FALSE  1 9.1 9 
> 
2

같은 문제가 있습니다.
기본 패키지를 다시 설치 한 후에도 오류 메시지가 계속 나타납니다.

결국 은 ggplot2 뒤에로드 된 lme4 패키지에 있습니다.
ggplot2::fortify(utah, region="id")을 사용하면 문제가 해결됩니다.