1

Hopefully a straightforward question but I made a simple figure in R using filled.contour(). It looks fine, and what it should like given the data. However, I want to add a reference line along a contour for 0 (level = 0), and the plotted line doesn't match the colors on the filled.contour figure. The line is close, but not matching with the figure (and eventually crossing over another contour from the filled.contour plot). Any ideas why this is happening?

aa <- c(0.05843150,  0.11300040,  0.15280030,  0.183524400,  0.20772430,  0.228121000)
bb <- c(0.01561055,  0.06520635,  0.10196237,  0.130127650,  0.15314544,  0.172292410)
cc <- c(-0.02166599,  0.02306650,  0.05619421,  0.082193680,  0.10334837,  0.121156780)
dd <- c(-0.05356592, -0.01432910,  0.01546647,  0.039156660,  0.05858709,  0.074953650)
ee <- c(-0.08071987, -0.04654243, -0.02011676,  0.000977798,  0.01855881,  0.033651089)
ff <- c(-0.10343798, -0.07416114, -0.05111547, -0.032481132, -0.01683215, -0.003636035)
gg <- c(-0.12237798, -0.09753544, -0.07785126, -0.061607548, -0.04788856, -0.036169540)

hh <-rbind(aa,bb,cc,dd,ee,ff,gg)

z <- as.matrix(hh)
y <- seq(0.5,1.75,0.25)
x <- seq(1,2.5,0.25)

filled.contour(x,y,z,
           key.title = title(main=expression("log"(lambda))),
           color.palette = topo.colors) #This works

contour(x,y,z, level=0,add=T,lwd=3) #This line doesn't match plot
  • 2
    You really should include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Include sample input data and the code you've tried so far. – MrFlick Jun 02 '15 at 19:06
  • @MrFlick Sorry—I figured it was straightforward without the code. I added some above. – Steve Midway Jun 03 '15 at 01:28

1 Answers1

1

This is completely answered in the ?filled.contour help page. In the Notes section it states

The output produced by filled.contour is actually a combination of two plots; one is the filled contour and one is the legend. Two separate coordinate systems are set up for these two plots, but they are only used internally – once the function has returned these coordinate systems are lost. If you want to annotate the main contour plot, for example to add points, you can specify graphics commands in the plot.axes argument. See the examples.

And the examples given in that help page show how to annotate on top of the main plot. In this particular case, the correct way would be

filled.contour(x,y,z,
    key.title = title(main=expression("log"(lambda))),
    color.palette = topo.colors,
    plot.axes = {
        axis(1)
        axis(2)
        contour(x,y,z, level=0,add=T,lwd=3)             
    }
)

which produces

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Thank you. I read the notes section and figured it was something related to the fact that two plots/coordinates are used, I just couldn't get my example to work. Thanks. – Steve Midway Jun 03 '15 at 10:57