[R] Suppressing internal grid in filled.contour

Dieter Menne dieter.menne at menne-biomed.de
Thu Oct 30 09:02:14 CET 2008


Jonathan Greenberg <greenberg <at> ucdavis.edu> writes:

> 
> Ok, I've placed the input files and the PDF on a website 
> http://www.cstars.ucdavis.edu/~jongreen/temp/
> 
This an aliasing problem that disappears partially when using higher 
resolution, as noted in the quoted 

# http://finzi.psych.upenn.edu/R/Rhelp02a/archive/90744.html

of my first message (did you check it?).

Dieter

library(akima)
# Providing data on the net as you did is fine, but you can make 
# life easier by directly providing the file url
urlt = url("http://www.cstars.ucdavis.edu/~jongreen/temp/tahoedata02.csv")
tahoecontourdata<-read.csv(urlt,header=TRUE)
x=tahoecontourdata$Elevation_Bin
y=tahoecontourdata$PRR
z=tahoecontourdata$MaxStems

# For easier reading, don't put too much into one expression, 
# but split it
steps = 600 # fine grid
intp = interp(x,y,z,duplicate="strip",
       xo=seq(1800,3200,length=steps),
       yo=seq(120,280,length=steps))
col=grey.colors(33,start=0,end=1,gamma=1)

pdf("tahoe.pdf")
# even at this resolution, the pdf picture has ugly kinks
filled.contour(intp,col=col, nlevels=33,zlim=0:650)
dev.off()

# This was the workaround in 
# http://finzi.psych.upenn.edu/R/Rhelp02a/archive/90744.html
pdf("tahoe1.pdf")
image(intp$x,intp$y,intp$z,col=col)
dev.off()

# or use lattice (but needs some additional massaging)
gr = expand.grid(x=intp$x,y=intp$y)
gr$z= as.vector(intp$z)
gr = na.omit(gr)

library(lattice)
pdf("tahoe2.pdf")
p = contourplot(z~x+y,data=gr,region=TRUE)
print(p)
dev.off()



More information about the R-help mailing list