パッケージggplot2の関数fortifyを使用して、空間オブジェクトをdata.frameに変換しようとしています。しかし、私はエラーが発生しています。たとえば、Hadley Wickhan のプロット ポリゴン シェープファイルの例で使用されているコードとまったく同じコードに従って、次のコマンド行を入力します。
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
utah@data$id = rownames(utah@data)
すべてが正常に動作しているようです:
> str(utah)
..@ 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" ...
...
...
ただし、パッケージケージ ggplot2 から関数 fortify を使用して utah オブジェクトを変換しようとすると、次のエラーが発生します。
> 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')"
fortify を使用して変換しようとした他のすべての空間オブジェクトで同じエラーが発生します。過去に (R のバージョン 3.0.2 にアップグレードする前に) 問題なく動作したコードを使用している場合でも。
Intel Core i7 と 16GB の RAM を搭載した Mac で R バージョン 3.0.2 を実行しています。