0

如何更改此图中的以下内容?

  1. 更改趋势线的颜色(当前为蓝色)
  2. 更改峰值点的颜色(当前为橙色)
  3. 更改时间序列模式线的颜色(当前为黑色)
  4. 添加图例以指示以上所有三个的颜色

这是我从代码源中得到的情节

在此处输入图像描述

代码来源:

# Libraries used: 
library(ggplot2)
library(timeSeries)
library(ggfortify)
library(ggthemes)
library(dplyr)
library(strucchange)

strucchange::breakpoints(AirPassengers ~ 1) %>%
  autoplot(ts.linetype = 'solid', ts.size = 1.1, ts.geom = 'line')+
  geom_smooth(aes(y=AirPassengers), 
              method = "loess", se= F,
              lwd = 1.2) +
  geom_point(aes(y = AirPassengers), size = 1.5, shape = 16, color = "orange3")+
  scale_x_date(date_breaks = "1 years", date_labels = "%Y")+
  labs(title = "Yearly Time Series", 
       subtitle="Sales trend from Year 2001 to 2017", 
       caption="Source: Airpassengers Time Series Analysis", 
       y="Sales", x = "Years")+
  theme_economist_white()+
  theme(axis.text.x = element_text(angle = 90, hjust = -.1))
4

1 回答 1

0

可以使用以下语法进行前三个更改:

strucchange::breakpoints(AirPassengers ~ 1) %>%
  autoplot(ts.linetype = 'solid', ts.size = 1.1, ts.geom = 'line', fill = "red")+
  geom_smooth(aes(y=AirPassengers), 
          method = "loess", se= F,
          lwd = 1.2, color = "green") +
  geom_point(aes(y = AirPassengers), size = 1.5, shape = 16, color = "blue")+
  scale_x_date(date_breaks = "1 years", date_labels = "%Y")+
  labs(title = "Yearly Time Series", 
   subtitle="Sales trend from Year 2001 to 2017", 
   caption="Source: Airpassengers Time Series Analysis", 
   y="Sales", x = "Years")+
 theme_economist_white()+
 theme(axis.text.x = element_text(angle = 90, hjust = -.1)) 

在此处输入图像描述

color = "green"通过在对 的调用中指定来更改趋势线的颜色geom_smooth。中的峰值点也是如此geom_point。最后,autoplot在这种情况下似乎不知道color,但它适用于指定fill = "red"(这会引发警告,但仍然有效)。

我不清楚你希望你的图例看起来如何,你能在评论中澄清一下吗?

于 2018-06-20T08:09:41.817 回答