0
votes

I want to put the same gradient colours as the legend, but in the bars, not in numbers. How I do it?

ggplot(francia, aes(x = reorder(Equipo, Gls.), y = Gls., colour = Gls.)) +
    geom_col( aes()) + 
    labs(title = "Goles por equipo", x="Equipos", y= "Goles") +
    geom_text(aes(label = Gls.), nudge_y = 2) + 
    coord_flip() +
    scale_colour_gradient(name = 'Goles', 
                          low = "Black", high = "green") +
    theme(panel.background = element_rect(fill = "grey"), strip.background = element_rect(fill="francia"))

This is my plot

1

1 Answers

0
votes

All you need to do is switch the color aesthetic to the fill aesthetic.

ggplot(francia, aes(x = reorder(Equipo, Gls.), y = Gls., fill = Gls.)) +
    geom_col( aes()) + 
    labs(title = "Goles por equipo", x="Equipos", y= "Goles") +
    geom_text(aes(label = Gls.), nudge_y = 2) + 
    coord_flip() +
    scale_fill_gradient(name = 'Goles', 
                          low = "Black", high = "green") +
    theme(panel.background = element_rect(fill = "grey"), strip.background = element_rect(fill="francia"))