[R] contourplot lines, text, and mtext

Richard D. Morey moreyr at missouri.edu
Fri Sep 7 03:28:58 CEST 2007


If I have a contourplot (in the lattice package) and I want to add 
straight lines to it, how do I do this?

I see that there are llines() and lsegement() functions for lattice 
plots, but they don't seem to do anything in this case:

library(lattice)
library(KernSmooth)
x=rnorm(10000)
y=x+rnorm(x,0,.5)
a=bkde2D(cbind(x,y),.7)
z=as.vector(a$fhat)
grid=expand.grid(x=a$x1,y=a$x2)
grid$z=z
contourplot(z~x*y,data=grid,region=T,col.regions=gray(seq(1,0,len=255)),colorkey=T,cuts=50,contour=F)
llines(x=c(-5,5),y=c(-5,5))
 > NULL
lsegments(x0=-5,y0=-5,x1=5,y1=5)

I'm just trying to do the equivalent of abline(0,1) on the plot.

ltext(), on the other hand, seems to like to place text in the upper 
left corner of the plot. I suspect that I misunderstand the coordinate 
system that lattice uses for contour plots. Can anyone enlighten me?

Richard


-- 
Richard D. Morey, M.A.
Research Assistant, Perception and Cognition Lab
University of M
issouri-Columbia



More information about the R-help mailing list