add the same density curve to a plot in R
问题 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 回答1: 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)) 来源: https://stackoverflow.com/questions