gpt4 book ai didi

r - 在GGally::ggpairs中编辑单个ggplots:如何在ggpairs中不填充密度图?

转载 作者:行者123 更新时间:2023-12-04 06:57:26 25 4
gpt4 key购买 nike


library(GGally)

data(diamonds, package="ggplot2")
diamonds.samp <- diamonds[sample(1:dim(diamonds)[1],200),]

# Custom Example
ggpairs(
diamonds.samp[,1:5],
mapping = ggplot2::aes(color = cut),
upper = list(continuous = wrap("density", alpha = 0.5), combo = "box"),
lower = list(continuous = wrap("points", alpha = 0.3), combo = wrap("dot", alpha = 0.4)),
diag = list(continuous = wrap("densityDiag")),
title = "Diamonds"
)

我懂了

enter image description here

如何使对角线密度图不被填充而仅显示线条?

有点作品...但不是真的。

就代码而言,这确实很丑陋,因为对我而言这没有任何意义。同样,它在这里不起作用,因为它也会改变直方图。
ggpairs(
diamonds.samp[,1:5],
mapping = ggplot2::aes(color = cut),
upper = list(continuous = wrap("density", alpha = 0.5), combo = "box"),
lower = list(continuous = wrap("points", alpha = 0.3), combo = wrap("dot", alpha = 0.4)),
diag = list(continuous = wrap("densityDiag"), mapping = ggplot2::aes(fill=carat)),
title = "Diamonds"
)

enter image description here

最佳答案

问题的答案可以在https://cran.r-project.org/web/packages/GGally/vignettes/ggpairs.html(archived here)上找到

ggally_mysmooth <- function(data, mapping, ...){
ggplot(data = data, mapping=mapping) +
geom_density(mapping = aes_string(color="cut"), fill=NA)
}
ggpairs(
diamonds.samp[,1:5],
mapping = aes(color = cut),
upper = list(continuous = wrap("density", alpha = 0.5), combo = "box"),
lower = list(continuous = wrap("points", alpha = 0.3), combo = wrap("dot", alpha = 0.4)),
diag = list(continuous = ggally_mysmooth),
title = "Diamonds"
)

enter image description here

关于r - 在GGally::ggpairs中编辑单个ggplots:如何在ggpairs中不填充密度图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34727408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com