使用 r 中的格子在一个图上叠加多条密度曲线

Overlay multiple density curves on one plot using lattice in r

我正在使用的数据是来自 nutshell 包的 births2006.smpl。使用 lattice 中的 densityplot() 函数,我能够生成如下所示的图形:

为此我简单地使用了:

densityplot( ~ births2006.smpl$DBWT | births2006.smpl$DPLURAL, plot.points=FALSE, xlab="Birth Weight", layout=c(1,5))

现在,我试图将所有这些密度曲线叠加到一个密度图上,我一直认为可以使用 densityplot() 函数来实现,但经过数小时的尝试但没有成功我不完全确定。这是我想创建的情节:

您需要使用 groups 参数。

library(nutshell)
data(births2006.smpl)

densityplot(~ DBWT, groups = DPLURAL, data = births2006.smpl,
            plot.points = FALSE, xlab = "Birth Weight")