user14692575
user14692575

Reputation:

How to change `ggplot2` output to grey level?

I am looking for a smooth way to change a ggplot2 output to grey level.

Here an example:

iris <- iris

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

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

Output

And what I wish to have is a scheme like this:

What I would like to have

To be honest, I am unable to solve my "problem" with ggplot2's cheatsheet. I think I need sth. like + scale_color_grey(start = 0.8, end = 0.2) or + scale_fill_grey(start = 0.8, end = 0.2).

Thanks!

Upvotes: 0

Views: 342

Answers (1)

teunbrand
teunbrand

Reputation: 38063

I'm not quite sure where the confusion is coming from, as your intuition seems totally correct to me. When I use the scale_colour_grey() is does exactly what you would expect and what you describe should be the outcome.

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

enter image description here

If you want the species/grey level order reversed, you can set limits in the scale, e.g.:

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

Upvotes: 1

Related Questions