设置 alpha 并删除 ggpairs 中密度图的黑色轮廓
Set alpha and remove black outline of density plots in ggpairs
考虑这个例子:
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
但黑线依然存在
感谢@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 中找到。请参阅 "Matrix Sections" 和 "Plot Matrix Subsetting"。
试试这个:
pm <- ggpairs(tips, mapping = aes(color = sex, alpha = 0.7), columns = c("total_bill", "time", "tip"))
考虑这个例子:
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
但黑线依然存在
感谢@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 中找到。请参阅 "Matrix Sections" 和 "Plot Matrix Subsetting"。
试试这个:
pm <- ggpairs(tips, mapping = aes(color = sex, alpha = 0.7), columns = c("total_bill", "time", "tip"))