Luiz Scheuer
Luiz Scheuer

Reputation: 335

How to rename line label in R autoplot?

I have the following plot with true values (black line), fitted values (orange line) and forecasts (blue line).

If you notice on the right, the fitted values line says NULL. How can I change that to "Fitted Values"?. Also, why does it say "series on top"? How can I change that as well?

Here s my code:

data <- read.csv('C:/users/Datasets/Final Datasets/final_a.csv', TRUE, ",")
y <- msts(data$MeanTravelTimeSeconds, start=c(2016,1), seasonal.periods=c(7.009615384615385, 30.5, 91.3, 365.25))

fit <- tbats(y)
fc <- forecast(fit)

# Generating the plot:
autoplot(y) + autolayer(fitted(fit)) + autolayer(fc)

enter image description here

Upvotes: 0

Views: 750

Answers (1)

DaveArmstrong
DaveArmstrong

Reputation: 21937

What about this:

autoplot(y) + 
  autolayer(fitted(fit)) + 
  autolayer(fc) + 
  scale_colour_manual(values="red", label="New Color Labsl", name="New Series Label") ```

scale_colour_manual() lets you change the colour and the attached label and the name applied to it.

Upvotes: 1

Related Questions