向R中的图添加相同的密度曲线 [英] add the same density curve to a plot in R
本文介绍了向R中的图添加相同的密度曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何从R中的 lattice
包中向 xyplot()
添加相同的密度曲线(请参见下面的可复制代码)?
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
推荐答案
我们可以使用 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))
这篇关于向R中的图添加相同的密度曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文