【问题标题】:Edit individual ggplots in GGally::ggpairs: How do I have the density plot not filled in ggpairs?在 GGally::ggpairs 中编辑单个 ggplots:如何使密度图未填充 ggpairs?
【发布时间】:2016-01-11 17:19:17
【问题描述】:

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

【问题讨论】:

标签: r ggplot2 ggally


【解决方案1】:

问题的答案可以在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"
)

【讨论】:

猜你喜欢
  • 2015-05-06
  • 1970-01-01
  • 2015-08-31
  • 2015-04-10
  • 1970-01-01
  • 1970-01-01
  • 2014-05-05
  • 2016-05-07
  • 2020-11-21
相关资源
最近更新 更多