Skip to content

Plotting a polygon with xyplot

3 messages · markm0705, Ken Knoblauch, Bert Gunter

#
Dear R helpers

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 

--
View this message in context: http://r.789695.n4.nabble.com/Plotting-a-polygon-with-xyplot-tp3870788p3870788.html
Sent from the R help mailing list archive at Nabble.com.
#
markm0705 <markm0705 <at> gmail.com> writes:
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"))