[R-sig-Geo] fortify.SpatialPolygonsDataFrame error

Paul Hiemstra paul.hiemstra at knmi.nl
Mon Feb 27 11:27:11 CET 2012


On 02/23/2012 04:48 PM, marion le texier wrote:
> Hi everyone, 
>
> I would like to know if someone of you has already got troubles when trying to use ggplot2 with a shape file?
> Here is what I've done:
>
> NUTS1<-readShapeSpatial("nuts1_2003", proj4string=CRS(projargs=("+init=epsg:3035")),IDvar="NUTS1")
> plot(NUTS1)
>
> NUTS1 at data$id <- rownames(NUTS1 at data) 
>
> # as codes are characters and not numeric values, I've changed them into:
>
> test<-as.numeric(seq(1:94))
> NUTS1 at data$id<-test
>
> NUTS1.points <- fortify.SpatialPolygonsDataFrame(NUTS1, region="id")
>
> # The function doesn't want to be applied and I get this error message:
>
> Erreur dans unionSpatialPolygons(cp, invert(polys)) : input lengths differ
> De plus : Message d'avis :
> In split(as.numeric(row.names(attr)), addNA(attr[, region], TRUE)) :
>   NAs introduits lors de la conversion automatique
>
> (sorry for the French comments...)
>
>
> # What I would like to do at the end is :
>
> NUTS1.map <- ggplot()+geom_polygon(data=NUTS1.points, aes(long, lat, group=group), fill=NA, colour="black") + coord_map()
>
>
> Do you have any idea of what I'm doing wrong?
>
> Thanks you very much for your help!!!
> Marion
>
>  		 	   		  
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Hi Marion,

I have used fortify succesfully many times, so without a reproducible
example which reproduces your error, I have a hard time helping you.
Some notes:

- Try fortify(NUTS1, region = "id") on the unaltered NUTS1 object, i.e.
just after calling readShapeSpatial. If this works, the problem is not
in fortify, but in your code.
- There is no need to call fortify.SpatialPolygonsDataFrame explicitely,
fortify(NUTS1, region = "id") will do the job. The function will deduce
from its input object that it need to use fortify.SpatialPolygonsDataFrame.

good luck,
Paul

-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770



More information about the R-sig-Geo mailing list