1

I'm trying to learn how to plot shapefiles with ggplot2 and I found a wiki at:

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

I downloaded and extracted the zip file provided into new directory on my desktop ( http://www.epa.gov/nheerl/arm/documents/design_doc/ecoregion_design.zip ).

I started reading through the article, going line by line but I'm running into a problem with 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

I looked at the ?fortify help page and get the jist of how it should be used. I think its being used correctly. I also found another question with the same error on SO,

Getting error while using fortify function in R (ggplot)

but I can't figure out how to apply what is being said for my solution. I might help if I had access to dropbox right now but I don't.

1

1 Answer 1

2

The short answer is to install the rgeos package and include it at the top.

A longer answer can be found here (and elsewhere): https://stat.ethz.ch/pipermail/r-sig-geo/2012-July/015685.html

Sign up to request clarification or add additional context in comments.

7 Comments

Installing and loading the rgeos package is not solving the problem immediately. I'll try and read through the link. it seems like it is not defaulting to rgeos but is instead using gpclib. the same error remains.
Did you reload maptools after installing and loading rgeos? I remember having this problem myself and eventually getting it to work, but am having trouble retracing my steps. But you definitely can do it without gpclib.
I just tried reloading maptools after rgeos but no luck. does the example work for you?
Here's a project where I use it. If I have some time later I can reduce it to a MWE, but most of what you need is toward the top: github.com/maxliving/stopnfrisk/blob/master/programs/….
One issue might be OS. What are you running? I've gotten this working on Mac and Unix, but haven't tried on Windows.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.