更改 R 中 GGally::ggpairs 中的基色?

问题描述 投票:0回答:1

如何在

ggpairs()
库的
GGAlly
函数中更改基色?

我想要一种任意颜色用于

ggpairs()
给出的所有绘图。有没有简单的方法可以实现这一点?

我根据数据中的某些协变量找到了有关着色的答案,例如在 ggpairs 的参数中使用

ggplot2::aes()
。我可以设法让它使用我认为默认调色板中的第一种颜色
ggpairs2::aes(color = "AnyThingSeemsToWorkHere")
。但我只想要一种任意颜色,比如紫色,而不是默认的灰色。

编辑:我通过做找到了一种方法

ggpairs(x, mapping = ggplot2::aes(colour = "AnythingSeemsToWorksHere")) + 
  scale_fill_manual(values = c("purple")) + 
  scale_color_manual(values = c("purple"))

可以完成这项工作,但我不喜欢像上面所做的那样将颜色映射到不存在的协变量,所以我仍然想知道是否有一些更基本或更优雅的方法来做到这一点。

r ggplot2 colors ggally
1个回答
0
投票

查看文档和示例后,我认为没有简单的方法可以更改默认值。基本上,默认值继承自

ggplot2
。但是,除了在
color
aes 上映射常量的选项之外,
GGally
还提供
wrap_
系列函数,可用于设置或更改默认参数。

这是一个基本示例,使用

wrap()
ggpairs
的默认示例上设置颜色构建:

library(GGally)
#> Loading required package: ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2

data(flea)

ggpairs(flea,
  columns = 2:4,
  lower = list(continuous = wrap("points", color = "purple")),
  diag = list(continuous = wrap("densityDiag", color = "purple")),
  upper = list(continuous = wrap("cor", color = "purple"))
)

© www.soinside.com 2019 - 2024. All rights reserved.