gpt4 book ai didi

r - ggplot2 的功能强化错误

转载 作者:行者123 更新时间:2023-12-03 18:31:18 25 4
gpt4 key购买 nike

我正在尝试使用 ggplot2 包中的 fortify 函数将空间对象转换为 data.frame。但我收到一个错误。例如,遵循 Hadley Wickhan's plotting polygon shapefiles example 中使用的完全相同的代码,我输入以下命令行:

 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" ...
...
...

但是,当我尝试使用 packcage 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 内存的 Mac 上运行 R 版本 3.0.2。

最佳答案

我遇到了同样的问题。
重新安装主要软件包后,错误消息仍然存在。

最终我意识到一个函数 fortify也存在于包装中 lme4ggplot2 之后加载的.
使用 ggplot2::fortify(utah, region="id")解决了这个问题。

关于r - ggplot2 的功能强化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19198544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com