[R] R extract vertices for polygon
David Winsemius
dwinsemius at comcast.net
Wed Jul 22 14:14:41 CEST 2009
On Jul 21, 2009, at 10:18 PM, Angel Marley wrote:
>
> Dear R users,
> I'm trying to extract from a given matrix (GROUP) the coordinates of
> the vertices of the different groups (i.e. 3, 7, 1 . . .) to plot
> the polygons to delineate the area in which each group "wins" and
> colour it diferentially. I can make a simple point plot, but I would
> like to add polygons with full colored area. The example is with a
> 5x5 matrix, but I'm working with 500 x 500 matrix, so hand work is
> difficult,
> Any suggestion will be welcomed.
>
> Nrep=5
> GROUP<-
> matrix(c(3,3,3,3,7,3,3,3,3,7,1,3,3,3,7,1,3,3,3,7,1,1,4,4,0),Nrep,Nrep)
> column<- seq(1, 5, length=Nrep)
> row<- seq(0,10,length=Nrep)
>
> colnames(GROUP)<- round(column,3)
> rownames(GROUP)<- row
>
> GROUP
>
> grupovec<-as.vector(GROUP)
> flushvec<-rep(column,rep(Nrep,Nrep))
> MORvec<-rep(row,Nrep)
>
> plot(flushvec,MORvec, col=grupovec, pch=19)
>
> polygon() # ????????????????????????????????????
>
> Thanks
> Angel
I am having trouble figuring out what variables represents
coordinates, but that's probably my problem and it's clear in your
head. There are several convex hull functions that you can find with:
<http://search.r-project.org/cgi-bin/namazu.cgi?query=convex+hull&max=100&result=normal&sort=score&idxname=functions&idxname=Rhelp08&idxname=views
>
Or if the wrapping breaks that URL just:
http://search.r-project.org/
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list