[R] contour plot, failing to interpolate through all data

Folkes, Michael Michael.Folkes at dfo-mpo.gc.ca
Wed Nov 5 00:28:21 CET 2008


I'm having trouble making contour lines for this attached, sparse
dataset (low data:NA ratio!).  Is it the high number of NA's, or funny
layout of the densities, or something else that's causing this?  This is
a subsample of the dataset, and I get the same problem when using the
full data. The only reason I get any contours is because I'm forcing
specific levels.  If no levels are declared, no contours are generated.
Please excuse my hack job at coding.
thanks in advance!
Michael

####start data to be in file='testmatrix.csv'

"0.5","1","1.5","2","2.5","3"
"-0.833",NA,NA,NA,NA,NA,21.05
"-0.8",NA,NA,NA,NA,10.62,NA
"-0.75",NA,NA,NA,5.13,NA,NA
"-0.667",NA,NA,2.24,NA,NA,11.68
"-0.6",NA,NA,NA,NA,5.69,NA
"-0.5",NA,0.74,NA,2.53,NA,5.81
"-0.4",NA,NA,NA,NA,2.59,NA
"-0.333",NA,NA,0.86,NA,NA,2.59
"-0.25",NA,NA,NA,0.89,NA,NA
"-0.2",NA,NA,NA,NA,0.9,NA
"-0.167",NA,NA,NA,NA,NA,0.9
"0",0,0,0,0,0,0
"0.2",NA,NA,NA,NA,-0.47,NA
"0.25",NA,NA,NA,-0.47,NA,NA
"0.333",NA,NA,-0.47,NA,NA,NA
"0.5",NA,-0.46,NA,-0.72,NA,NA
"0.667",NA,NA,-0.72,NA,NA,NA
"1",-0.42,-0.72,-0.85,NA,NA,NA
"1.5",NA,-0.85,NA,NA,NA,NA
"2",-0.69,-0.92,NA,NA,NA,NA
"3",-0.84,NA,NA,NA,NA,NA
"4",-0.91,NA,NA,NA,NA,NA
"5",-0.95,NA,NA,NA,NA,NA

####End data

####start code
junk2<-as.matrix(read.csv(file='testmatrix.csv'))
colnames(junk2)<-as.character(seq(.5,3,by=.5))
contour(ylim=c(-1,1),as.numeric(rownames(junk2)),as.numeric(colnames(jun
k2)),  junk2,levels=c(seq(-1,0,by=.1),seq(1,23,by=2)))
junk3<-cbind(as.numeric(colnames(junk2)[as.vector(col(junk2))]),as.numer
ic(row.names(junk2)[as.vector(row(junk2))]),as.numeric(as.vector(junk2))
)
text(junk3[,1],junk3[,2],junk3[,3],cex=.5)

#### End code

_______________________________________________________
Michael Folkes
Salmon Stock Assessment
Canadian Dept. of Fisheries & Oceans     
Pacific Biological Station
3190 Hammond Bay Rd.
Nanaimo, B.C., Canada
V9T-6N7
Ph (250) 756-7264 Fax (250) 756-7053  Michael.Folkes at dfo-mpo.gc.ca



More information about the R-help mailing list