自定义ggplot中图形的颜色

Customise colors of graphs in ggplot


自定义ggplot中图形的颜色 已获得1个解决方法 2020-08-18 18:07:32 r

我正在尝试自定义ggplot的颜色.我在一个图中有11个时间线的图,现在想自定义它们的颜色.起初我给颜色命名是这样的:

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

比我把ggplot从

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"))

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

结果是警告

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")

我想绘制线 (点外),所以我采取了geom_line,但这不起作用,你可以看到.

我错过了什么吗?


自定义ggplot中图形的颜色 方法1

尝试将其添加到您的原始代码中:

do i need to throw an exception or does the computer automatically throws one at runtime?

如果您可以提供原始数据,那将非常有帮助,因为我现在有点在黑暗中拍摄.


.htaccess .net .net-core 2d 3d 3d-printing ab-initio abp abstract-syntax-tree actions-on-google actionscript-3 active-directory activemq activemq-artemis acumatica adobe-xd aframe ag-grid agora.io air airflow ajax akka alert alexa algorithm alignment allure amadeus amazon-cloudformation