How to change colors of ggplot chart?

Asked

Viewed 760 times

3

The code below generates a graph of lines whose colors are automatically set to blue and red:

ggplot(aes(x = factor(year), y1 = auto_course_choice, y2 = auto_hire, group=country)) +
  geom_line(aes(y = auto_course_choice, colour = "autonomy course decision")) + facet_wrap(~ country, ncol = 7) + 
  theme_bw()+
  geom_line(aes(y = auto_hire, colour = "autonomy hiring teachers")) + 
  facet_wrap(~ country, ncol = 7) + 
  theme_bw()

How it is possible to change the colors of the lines generated by geom_line() on a chart ?

  • Hello Michelle, you need to specify which colors you want to change? the line color? The background color? If it is clearer, your question is more likely to be answered.

  • ok, thanks! I want to change the color of the lines of the chart that looks are automatic to blue and red!

  • Can you please, edit the question with the departure of dput(dados) or, if the base is too large, dput(head(dados, 20))? Note: dados is the base name, for example a data frame..

  • @Noisy sure you need it to answer the question?

  • @Danielfalbel Absolutely necessary maybe not, I can create a data set. But you’ve seen the color in the code above? colour = "autonomy hiring teachers" is not an absolute certainty base variable.

  • @Danielfalbel Also missing the argument data in ggplot().

  • That’s why she is forcing the color straight. I wanted to open the question even...

  • Can’t reopen after she commented it’s the lines generated by geom_line()?

  • Or indicate this question as already containing the answer... (@Danielfalbel and @Ruibarradas)

  • Yes, but it needs 5 votes to reopen. I think this question answers only the gradient, hers is a categorical scale.

  • Can use colour = c("blue", "red"). But what is there is not a color name. That seems to be the main problem. Anyway, I will vote to reopen.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.