当前位置:  开发笔记 > 前端 > 正文

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

如何解决《在GGally::ggpairs中编辑单个ggplots:如何在ggpairs中填充密度图?》经验,为你挑选了1个好方法。

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"
)

我明白了

在此输入图像描述

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

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

这在代码方面真的太丑了 - 因为它对我来说没有任何意义.此外,它在这里不起作用,因为它也改变了直方图.

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"
)

在此输入图像描述



1> Make42..:

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

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"
)

在此输入图像描述

推荐阅读
pan2502851807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有