Amir Valizadeh
Amir Valizadeh

Reputation: 73

ggplot aes fill for continous values is always in blue?

Here is the code:

ggplot() + geom_col(data = s, aes(x = V1, y = V3, fill = V3, alpha = 0.5), show.legend = F) + coord_flip()

V1 is a series of names, while V3 is a series of numbers. So the output image is like this:

enter image description here

Everything is perfect, the only problem is I want the fill color to be in the green range, not blue.

Upvotes: 0

Views: 44

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 173793

If you want something that works nicely out of the box you can use scale_fill_distiller with palette = "Greens" or palette = "YlGn"

set.seed(1)
s <- data.frame(V1 = LETTERS[1:20], V3 = runif(20, 0.2, 0.3))

ggplot(s) +
  geom_col(aes(x = V1, y = V3, fill = V3), alpha = 0.6) +
  coord_flip() +
  scale_fill_distiller(palette = 'Greens')

enter image description here

Upvotes: 3

Related Questions