I was wondering how I could add the same density curve to an xyplot()
from lattice
package in R ( see reproducible code below )?
library(lattice)
xyplot((1:32*.01)~wt|gear , data = mtcars)
lines(density(rnorm(1e3, 3.5))) # add this to all plot panes in `xyplot` above
We could use layer
library(lattice)
library(latticeExtra)
foo <- xyplot((1:32*.01)~wt|gear , data = mtcars)
foo +
layer(panel.densityplot(rnorm(1e3, 3.5), plot.points = FALSE))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.