Perfect. Thank-you!
"Deepayan Sarkar" <[EMAIL PROTECTED]> 06/07/2006 11:19 AM To "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> cc [email protected] Subject Re: [R] Fw: Help needed using lattice for area plots lpolygon, xyplot. On 6/7/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I am trying to learn how to use the graphics from the lattice package ( > and am very new to R). > > I am trying to replicate the example plot referenced below, by using the > lattice xyplot & lpolygon to create panels. I get what appears to be the > correct shape of the filled region, but cannot get the position to overlay > properly. I have attempted with various settings of position. ( i.e. > position = c(0,0,1,1) etc settings as well. I am not understanding > something about the positioning panels. I am missing some subtle > difference between polygon & lpolygon, or am missing something about panel > overlays &/or panel postions. > > #http://addictedtor.free.fr/graphiques/graphcode.php?graph=7. > par(bg="white") > n <- 100 > set.seed(43214) #just so we have the same exact graph > x <- c(0,cumsum(rnorm(n))) > y <- c(0,cumsum(rnorm(n))) > xx <- c(0:n, n:0) > yy <- c(x, rev(y)) > plot(xx, yy, type="n", xlab="Time", ylab="Distance") > polygon(xx, yy, col="gray") > title("Distance Between Brownian Motions") > > > > # using lattice. > p1 <- xyplot( yy~xx,type='l'); > p2 <- lpolygon(xx,yy,col='blue'); > print(p1,position=c(0,0,1,1), more=TRUE); > print(p2,position=c(0,0,1,1)); You are missing a fundamental concept in lattice, namely that of panel functions. A literal translation of that example would be xyplot(yy ~ xx, panel = lpolygon, col = "gray") which is more or less equivalent to xyplot(yy ~ xx, panel = function(x, y, ...) { # panel.xyplot(x, y, ...) # unnecessary lpolygon(x, y, col = "gray") }) The line commented out is the equivalent of plot(...type='n'), but is unnecessary here. Deepayan ------------------------------------------------------------ CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}} ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
