编辑GGally :: ggpairs中的单个ggplots:我如何让密度图未在ggpairs中填充? [英] Edit individual ggplots in GGally::ggpairs: How do I have the density plot not filled in ggpairs?

查看:270
本文介绍了编辑GGally :: ggpairs中的单个ggplots:我如何让密度图未在ggpairs中填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

  library(GGally)

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

#自定义示例
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 =钻石

I get





如何制作对角线密度图不能填充,只显示线条?



种类的作品...但不是真的。



这在代码方面确实很丑 - 因为它对m没有任何意义即

  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 =钻石

解决方案

问题的答案可以可在


With

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

I get

How do I make the diagonal density plots to not be filled, and only show the lines?

Kind of works... but not really.

This is really ugly - in terms of code - because it makes no real sense to me. Also, it does not work here, because it changes the histograms as well.

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

解决方案

The answer to the question can be found on 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"
)

这篇关于编辑GGally :: ggpairs中的单个ggplots:我如何让密度图未在ggpairs中填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆