[R-sig-Geo] maptools: appending data to SpatialPolygonsDataFrame
Roger Bivand
Roger.Bivand at nhh.no
Mon May 12 22:00:30 CEST 2008
On Tue, 29 Apr 2008, hkreft at ucsd.edu wrote:
> Dear all,
>
> I am just starting to use the library maptools. Specifically, I want to
> use it as a quick way to map results from various multivariate analyses
> (e.g. cluster analyses) directly in R.
> I encountered problems appending newly generated data (cluster
> memberships) to the SpatialPolygonsDataFrame object. Unfortunately, the
> documentation is not really helpful.
Dear Holger,
Sorry that this message did not get a reply - I'm afraid that your code
example is unhelpful, because it doesn't go far enough. Do you mean
something like:
library(maptools)
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
names(xx)
k5 <- kmeans(as(xx, "data.frame")[, 9:14], center=5)
str(k5)
xx$k5 <- factor(k5$cluster)
spplot(xx, "k5")
for a trivial example that can be reproduced?
Roger
>
> But I am sure that this is an easy question for you.
>
> Thanks in advance,
>
> Holger
>
>
> The code so far:
>
>>> my.polys <- readShapePoly("Z://mypoly.shp",IDvar="ID",verbose=T)
>>> plot(my.polys)
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list