I have data like this:
test_data <- data.frame(
var0 = 100 + c(0, cumsum(runif(49, -20, 20))),
var1 = 150 + c(0, cumsum(runif(49, -10, 10))),
date = seq.Date(as.Date("2002-01-01"), by="1 month", length.out=100))
To plot both time series var0 and var1 on the same graph, with date on the x-axis, using ggplot2
ggplot(test_data, aes(date)) +
geom_line(aes(y = var0, colour = "var0")) +
geom_line(aes(y = var1, colour = "var1"))
This will work fine and plot two time series in different colors but the title of Y axis and the legend will be"var0".
- How to change the title of Y axis and the legend to,for example,variable , value
- how to change the colors of both var0 and var1 lines
Thanks