[R] Formatting question for separate polygons

Uwe Ligges ligges at statistik.tu-dortmund.de
Fri Feb 12 12:14:15 CET 2010



On 11.02.2010 22:38, Tim Clark wrote:
> Dear List,
>
> I am trying to plot several separate polygons on a graph.  I have figured out how to do it by manually, but have too much data to use such a tedious method.  I would appreciate your help.  I have made a simple example to illustrate the problem.  How can I get x into the proper format (x1)?
>
> #Sample data
> x<-c(1,2,3,4,5,6)
> y<-c(1,2,2,1)
>
> #I need to format the data like this
> x1<-c(1,1,2,2,NA,3,3,4,4,NA,5,5,6,6,NA)
> y1<-rep(c(1,2,2,1,NA),length(x)/2)



x1 <- as.numeric(rbind(matrix(rep(x, each=2), nrow=2), NA))

Uwe Ligges


> #Final plot
> plot(c(1,6), 1:2, type="n")
> polygon(x1,y1,density=c(40))
>
>
> Thanks,
>
> Tim
>
>
> Tim Clark
> Department of Zoology
> University of Hawaii
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list