-1

I am trying to make a "smoothed" contour plot using the lattice package and curious if is any way to "ignore" half of the values in my matrix. A little difficult to explain but hopefully my code clarifies this question.

link to my data

https://www.dropbox.com/s/a1todt21f1wzkuk/data.matrix.xlsx

code:

#load necessary packages
require(xlsx)
require(lattice)
require(latticeExtra)

#import data
my.data<-read.xlsx("C:/Users/eckmannm/dropbox/data.matrix.xlsx", sheetName="1",row.names=TRUE) 
my.data.matrix<-as.matrix(my.data)

#make ranges for axis
Max.Depth.Values<-(c(1,2,4,6,8,10,12,14,16,18,20))
Trap.Depth.Values<-(c(1,2,4,6,8,10,12,14,16,18,20))

#specify color ramp
col.l <- colorRampPalette(c('red', 'orange', 'yellow', 'green', 'cyan', 'blue'))

#make lattice plot
(colorplot<-  
levelplot(
my.data.matrix, 
row.values=(Trap.Depth.Values),
column.values=(Max.Depth.Values),
col.regions=col.l,
at=seq(from=0,to=18,length=101),    
lattice.options=list(key=list(cex=4)),
aspect = "fill",
xlim=c(1,20),
ylim=c(1,20),
panel = panel.2dsmoother,
ylab=list("Trap Depth (m)",cex=1.4), 
xlab=list("Max Depth",cex=1.4), 
main=list("CPUE of Redside Shiners at Different Depths",cex=1.6),
colorkey=list(at=seq(from=0, to=18, length=80), 
              labels=list(at=c(0,3,6,9,12,15,18), 
                          labels=c("0","3", "6", "9","12", "15", "18")))))

With the code panel=panel.2dsmoother, I am able to create a smoothed image (see image 1 below), but this graph is completely misleading because I am trying to ignore all the values that are less than 1 (they should be left uncolored). When I don't use panel=panel.2dsmoother, I get a more "correct" image but it is very pixelated because I have too few values (see image 2 below).

image 1 image 2

Are there any suggestions or is this even possible?

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
madeckmann
  • 61
  • 1
  • 1
  • 5
  • The link t0 my data in my dropbox folder is at the top of the question (just above the R code). It seems to be working fine for me. Are you having an issue with the link? – madeckmann Feb 19 '14 at 21:30
  • Sorry; only saw the local path in the code. – Dieter Menne Feb 20 '14 at 07:06
  • Max.Depth.Values is undefined, I assume it is Trap.Depth.Values. It's a good idea to run you code in a freshly started R session before posting. – Dieter Menne Feb 20 '14 at 07:38

1 Answers1

0

R handles NA sensibly. Try to replace your negatives

my.data.matrix[my.data.matrix <0]=NA

Output of levelplot

Dieter Menne
  • 10,076
  • 44
  • 67
  • Thank you so much for your help and input. This plot you have made (with the NA's included) is the plot I DON'T want to make. For some reason, when I incorporate NA's the panel function, panel.2dsmoother makes this plot. Things are also screwy when I change the NA values to values below 0. I'm sorry I cannot get my images to display but what I want, is to have only white above the 1:1 diagonal. Does this make any sense? – madeckmann Feb 23 '14 at 18:22