[R] Formatting question for separate polygons
Tim Clark
mudiver1200 at yahoo.com
Thu Feb 11 22:38:16 CET 2010
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)
#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
More information about the R-help
mailing list