add the same density curve to a plot in R

谁说我不能喝 提交于 2020-05-28 07:02:45

问题


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/61643280/add-the-same-density-curve-to-a-plot-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!