Search code examples
rggplot2colorbrewer

I cannot apply a ColorBrewer palette on a line chart in ggplot2


p1 <- ggplot(data, aes(x, y, group=label))
p2 <- p1 + geom_line()+geom_point()
library(RColorBrewer)
p2 + scale_fill_brewer(palette="Oranges")

Sadly, I cannot post a image because of reputation limitation! The result is a line chart in with only black line and dots.

If I add "color=label" in the aes() part, the result uses the default color scheme, not my intended colors.

What should I do?


Solution

  • Something like this?

    require(ggplot2)
    df <- data.frame(a = seq(0, 90, 10), b = seq(10, 100, 10))
    ggplot(df, aes(a, b, group = 1, color = b)) + 
      geom_line() + geom_point() +
      scale_color_gradient(low = "green", high = "red")
    

    enter image description here