3

我正在尝试使用lattice库的densityplot功能来显示一些数据。我的数据集非常混乱,所以我想减少绘制在底部的符号的 alpha 值(这样你就可以更清楚地看到过度绘制的情况)。但是,如果不使实际密度曲线同样不透明,我似乎无法仅更改这些符号的 alpha 值。我正在使用图形的选项并为andpar.settings设置不同的值(这适用于更改线型和符号,但由于某种原因不能更改 alpha 值)。我使用 iris 数据集做了一个小例子来说明我的问题/当前方法。如果有人有任何建议,我将不胜感激。superpose.linesuperpose.symbol

library(lattice) 
data(iris) 

graph.settings <- list(superpose.line = list(lty = 1:3, lwd = 2, alpha = 1),
                       superpose.symbol = list(pch = 1:3, alpha = 0.3)) 
densityplot( ~ Sepal.Length, data = iris, groups = Species, 
            auto.key = list(columns = 3), aspect = 1, 
            main = "Density Plot of Sepal Lengths", xlab = "Length (mm)", 
            par.settings = graph.settings)
4

1 回答 1

6

这是一个快速的解决方案。它通过提供一个“自定义”面板函数来工作,该函数调用panel.densityplot()两次:第一次调用为您提供地毯点alpha=0.3;第二个用 覆盖密度曲线alpha=1

library(lattice) 
data(iris) 

graph.settings <- list(superpose.line = list(lty = 1:3, lwd = 2),
                       superpose.symbol = list(pch = 1:3)) 
densityplot( ~ Sepal.Length, data = iris, groups = Species, 
            auto.key = list(columns = 3), aspect = 1, 
            main = "Density Plot of Sepal Lengths", xlab = "Length (mm)", 
            par.settings = graph.settings,
            panel = function(x, ...) {
                panel.densityplot(x, ..., alpha = 0.3)
                panel.densityplot(x, ..., plot.points=FALSE, alpha = 1)
            })
于 2012-09-13T14:03:57.893 回答