polygon.r

tchsieh — Oct 11, 2013, 5:14 AM

dat <- read.table("http://dl.dropboxusercontent.com/u/14820071/cs_MP1_lc.txt", skip=9)
dat <- dat[,c(1,2)]
rd <- 0
x <- round(dat[ ,1], rd)
y <- round(dat[ ,2], rd)
plot(dat, col=adjustcolor(1, 0.25), xlab="X", ylab="Y") #all points, black dots
x0 <- seq(from=min(x), to=max(x), by=0.1^rd)
y0.min <- y0.max <- rep(0, length(x0))
for(i in seq_along(x0)){
  y0.min[i] <- min(y[which(x==x0[i])])
  y0.max[i] <- max(y[which(x==x0[i])])
}

plot(dat, col=adjustcolor(1, 0.25), xlab="X", ylab="Y") #all points, black dots

polygon(x=c(x0, rev(x0)), y=c(y0.min, rev(y0.max)), border=2, lwd=2) #Lazzy cover, red polygon

plot of chunk unnamed-chunk-1



out1 <- smooth.spline(x0, y0.min)
out2 <- smooth.spline(x0, y0.max)
y1.min <- out1$y
y1.max <- out2$y
plot(dat, col=adjustcolor(1, 0.25), xlab="X", ylab="Y") #all points, black dots
polygon(x=c(x0, rev(x0)), y=c(y1.min, rev(y1.max)), border=3, lwd=2) #smooth cover, green polygon

plot of chunk unnamed-chunk-1