设置alpha并删除ggpairs中密度图的黑色轮廓

时间:2016-01-24 11:29:44

标签: r ggplot2 ggally

考虑这个例子:

data(tips, package = "reshape")
library(GGally)
pm <- ggpairs(tips, mapping = aes(color = sex), columns = c("total_bill", "time", "tip"))
pm

enter image description here

如何使密度图更透明并删除黑线?

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

但黑线仍然存在。

2 个答案:

答案 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

enter image description here

有关如何自定义ggpairs图的示例,请参阅the vignette。请参阅“矩阵章节”和“绘制矩阵子集”。

答案 1 :(得分:2)

试试这个:

pm <- ggpairs(tips, mapping = aes(color = sex, alpha = 0.7), columns = c("total_bill", "time", "tip"))