Yuyu ZENG
Yuyu ZENG

Reputation: 273

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?

Upvotes: 0

Views: 1379

Answers (1)

lawyeR
lawyeR

Reputation: 7684

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

Upvotes: 1

Related Questions