【问题标题】:How to change `ggplot2` output to grey level?如何将`ggplot2`输出更改为灰度?
【发布时间】:2021-01-22 09:35:56
【问题描述】:

我正在寻找一种将ggplot2 输出更改为灰度级的平滑方法。

这里是一个例子:

iris <- iris

library(mlr3)
example <- TaskClassif$new(id = "iris", backend = iris, target = "Species")

library(GGally, ggplot2, mlr3viz)
autoplot(example, type = "pairs")

而我希望有这样一个方案:

说实话,我无法用ggplot2cheatsheet 解决我的“问题”。我想我需要某事。喜欢+ scale_color_grey(start = 0.8, end = 0.2)+ scale_fill_grey(start = 0.8, end = 0.2)

谢谢!

【问题讨论】:

标签: r ggplot2 colors


【解决方案1】:

我不太确定混乱来自哪里,因为您的直觉对我来说似乎完全正确。当我使用scale_colour_grey() 时,它完全符合您的预期,您所描述的应该是结果。

autoplot(example, type = "pairs") +
  scale_colour_grey(aesthetics = c("fill", "colour")) + # fill and colour at the same scale
  theme_classic() # Eliminite confusing grey background

如果您希望物种/灰度级顺序颠倒,您可以在比例中设置限制,例如:

autoplot(example, type = "pairs") +
  scale_colour_grey(aesthetics = c("fill", "colour"),
                    limits = rev(unique(iris$Species))) +
  theme_classic()

【讨论】:

  • 太棒了,谢谢!我忽略了将其写为astheticts = c("fill", "colour")。这可能是因为我没有使用ggplot2 的经验。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-04
  • 2014-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多