考虑这个例子:
data(tips, package = "reshape")
library(GGally)
pm <- ggpairs(tips, mapping = aes(color = sex), columns = c("total_bill", "time", "tip"))
pm
如何使密度图更透明并删除黑线?
GGally
软件包最近似乎发生了很大变化,我找不到可行的解决方案
更新
我找到了如何使用自定义函数更改alpha:
my_dens <- function(data, mapping, ..., low = "#132B43", high = "#56B1F7") {
ggplot(data = data, mapping=mapping) +
geom_density(..., alpha=0.7)
}
pm <- ggpairs(tips, mapping = aes(color = sex), columns = c("total_bill", "time", "tip"),
diag=list(continuous=my_dens))
pm
但黑线仍然存在。
答案 0 :(得分:11)
感谢@Henrik这是使用自定义功能的解决方案
my_dens <- function(data, mapping, ...) {
ggplot(data = data, mapping=mapping) +
geom_density(..., alpha = 0.7, color = NA)
}
pm <- ggpairs(tips, mapping = aes(color = sex), columns = c("total_bill", "time", "tip"),
diag = list(continuous = my_dens))
pm
有关如何自定义ggpairs
图的示例,请参阅the vignette。请参阅“矩阵章节”和“绘制矩阵子集”。
答案 1 :(得分:2)
试试这个:
pm <- ggpairs(tips, mapping = aes(color = sex, alpha = 0.7), columns = c("total_bill", "time", "tip"))