One color for each column

I want to get one colour per column in this example but I only get one uniform colour, what should I add?

df <- data.frame(
        date = c("2021-08-06","2021-08-05","2021-08-04",
       plant = c(16L,21L,18L,28L,29L,23L,23L,19L,16L,
        care = c(7L,7L,7L,7L,7L,7L,6L,6L,6L,5L,5L,

ggplot(df, aes(x = date, y = plant)) +
  geom_col() +
  scale_fill_identity(guide = "none", aesthetics = "fill")

I get this:

Is this what you want?

ggplot(df, aes(x = date, y = plant, fill = date)) +
  geom_col(show.legend = FALSE)

Yes, that's right, perfect

It's possible to change the colour palette? Thanks for your help

Select one of the scale_fill_*() options:
Function reference • ggplot2 (

Thanks again martin
But with any of the palettes I try to do it, I get this error message

In RColorBrewer::brewer.pal(n, pal) :
  n too large, allowed maximum for palette YlOrRd is 9
Returning the palette you asked for with that many colors

I'm not really sure why you are trying to get different colours per bar, but just define them manually. Discrete pre-defined palettes will not have the number of different colours you require for obvious reasons.

Alternatively, convert the date column to actual dates and use a continuous scale:

df$date <- as.Date(df$date)

ggplot(df, aes(x = date, y = plant, fill = date)) +
  geom_col(show.legend = FALSE) + 
1 Like

Got it, thanks a lot!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.