Customise colors of graphs in ggplot

2019-08-12 10:10发布

问题:

I'm trying to customize colors of a ggplot. I have a plot of 11 timelines in one plot an now want to customize their colors. At first i named the colors like that:

Colors_custom<-c("#000000","#00EEEE","#EEAD0E","#006400","#BDB76B","#EE7600","#68228B","#8B0000","#1E90FF","#EE6363","#556B2F")

Than I changed ggplot from

ggplot(timeline,aes(x=Year,y=value,color=Projection,group=Projection))+
geom_line(size=0.6) + xlab("Year") + ylab("Recharge [mm/a]") + 
ggtitle("Recharge") +  theme_bw() 
scale_x_continuous(breaks=c(1961,1980,2000,2020,2040,2060,2080,2100)) + 
theme(axis.title=element_text(size=15,face="bold"), title=element_text(size=15,face="bold"))

to

ggplot(timeline,aes(x=Jahr,y=value,color=Colors_custom,group=Projection))+ ...

Result was warning

Error: Aesthetics must either be length one, or the same length as the dataProblems:c("#000000", "#00EEEE", "#EEAD0E", "#006400", "#BDB76B", "#EE7600", "#68228B", "#8B0000", "#1E90FF", "#EE6363", "#556B2F")

i want to plot lines (out of points) so I took geom_line, but that does not work as you can see.

Did I miss something?

回答1:

Try adding this to your original code:

scale_colour_manual(values = Colors_custom)

It would be very helpful if you could supply your original data, as I am kind of shooting in the dark now.



标签: r ggplot2