Plotting a polygon with xyplot
markm0705 <markm0705 <at> gmail.com> writes:
I would like to plot a string of points as a polygon in xyplot. I'm a bit
lost as to how to get the points plotting in the correct order. I would
also like some hints on how to render or fill the polygon.
Scrpt below and data file attached
Thanks
Markm
library("lattice")
# set size of the window
windows(height=7, width=10,rescale=c("fixed"))
Data_poly<- read.table("111004_Lode_Outlines.csv",header = TRUE,sep = ",",)
xyplot(z~y,
data=Data_poly,
type="l"
) http://r.789695.n4.nabble.com/file/n3870788/111004_Lode_Outlines.csv
111004_Lode_Outlines.csv
Before you try this with lattice, you might spend some time
getting your abscissa values in an order that will plot the
contour in a sequential fashion. It's not obvious how to
do this a priori. Here is a simple-minded attempt after looking
at your graphic, just using base graphics. Maybe, it will
be sufficient for you to tweak it a bit further for what you
want.
Data_poly<-
read.table("http://r.789695.n4.nabble.com/file/n3870788/111004_Lode_Outlines.csv",
header = TRUE,sep = ",",)
par(mfrow = c(1, 2), pty = "s")
plot(z ~ y, Data_poly, type = "l")
fh <- with(Data_poly, which(z > 240))
D_poly <- rbind(Data_poly[fh, ], Data_poly[-rev(fh), ])
D_poly <- rbind(D_poly, Data_poly[1, ])
plot(z ~ y, D_poly, type = "n")
with(D_poly, polygon(y, z, col = "lightblue"))
Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen L?pine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html