如何使用R更改折线图中的颜色(自动)?

时间:2020-09-16 16:18:38

标签: r ggplot2

我正在尝试根据我的数据(年和雨)生成折线图。该图很好,但是我想(自动)更改每条线的颜色。代码在下面给出

scale_fill_brewer(palette="Oranges")

我正在尝试使用 Error: Continuous value supplied to discrete scale,但显示错误。 scale_fill_brewer(palette="Oranges")

我的没有java -Xmx256m -jar -Dspring.profiles.active=test /home/appuser/myapp.jar 的图表在下面给出

我的代码生成的RGraph: enter image description here

我需要像这样绘制(此图使用Python是精简的!)

我的预期图表: enter image description here

你能告诉我,我该怎么做?

2 个答案:

答案 0 :(得分:0)

尝试以下操作(由于缺少可重复的数据,因此未提供任何输出):

#Code
ggplot(data=data_1, aes(x=Year, y=rain, fill=factor(Year)))+
  geom_line(stat="identity")+
  theme_minimal()+
  geom_col(width = 0.05, position = position_dodge(0.7))+
  xlab("Year")+
  ylab("Rain")+
  ggtitle("Rain of every Year")+
  guides(fill = guide_legend(ncol = 1))

答案 1 :(得分:0)

很难看到真实的数据,但是我会尝试LOCK TABLE ... IN EXCLUSIVE MODE。这是包含测试数据的代码。

geom_segment

enter image description here