[R] R extract vertices for polygon

Angel Marley angel_nauti at yahoo.com
Wed Jul 22 04:18:51 CEST 2009


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




More information about the R-help mailing list