【问题标题】:Errors working through plotting shapefiles in the ggplot wiki在 ggplot wiki 中绘制 shapefile 时出错
【发布时间】:2014-02-13 18:19:28
【问题描述】:

我正在尝试学习如何使用 ggplot2 绘制 shapefile,我在以下位置找到了一个 wiki:

https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles

我下载并解压了提供的 zip 文件到我桌面上的新目录 (http://www.epa.gov/nheerl/arm/documents/design_doc/ecoregion_design.zip)。

我开始逐行阅读这篇文章,但我遇到了fortify 的问题。

require("rgdal")
require("maptools")
require("ggplot2")
require("plyr")

> my_dsn <- "directory here"
> 
>   utah = readOGR(dsn=my_dsn, layer="eco_l3_ut")
OGR data source with driver: ESRI Shapefile 
Source: "directory here", layer: "eco_l3_ut"
with 10 features and 7 fields
Feature type: wkbPolygon with 2 dimensions
>   utah@data$id = rownames(utah@data)
>   utah.points = fortify(utah, region="id")
Error: isTRUE(gpclibPermitStatus()) is not TRUE

我查看了?fortify 帮助页面并了解了应该如何使用它。我认为它被正确使用。我还在 SO 上发现了另一个同样错误的问题,

Getting error while using fortify function in R (ggplot)

但我不知道如何应用我的解决方案所说的内容。如果我现在可以访问保管箱,我可能会有所帮助,但我没有。

【问题讨论】:

标签: r ggplot2 gis maptools


【解决方案1】:

简短的回答是安装 rgeos 包并将其包含在顶部。

可以在此处(和其他地方)找到更长的答案:https://stat.ethz.ch/pipermail/r-sig-geo/2012-July/015685.html

【讨论】:

  • 安装和加​​载 rgeos 包并不能立即解决问题。我会尝试通读链接。似乎它没有默认为 rgeos,而是使用 gpclib。同样的错误仍然存​​在。
  • 您在安装和加载 rgeos 后是否重新加载了 maptools?我记得我自己也遇到过这个问题,并最终让它发挥作用,但是我在追溯我的步骤时遇到了麻烦。但你绝对可以不用 gpclib。
  • 我刚刚尝试在 rgeos 之后重新加载 maptools 但没有运气。这个例子对你有用吗?
  • 这是我使用它的一个项目。如果以后有时间,我可以将其简化为 MWE,但您需要的大部分内容都在顶部:github.com/maxliving/stopnfrisk/blob/master/programs/…
  • 一个问题可能是操作系统。你在跑什么?我已经在 Mac 和 Unix 上进行了这项工作,但还没有在 Windows 上尝试过。
猜你喜欢
  • 2018-11-11
  • 2020-10-23
  • 1970-01-01
  • 2020-10-08
  • 1970-01-01
  • 1970-01-01
  • 2018-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多