I am trying to switch from plot to ggplot2 and experience some real trouble. Below, I have attached a very simplified version of some code for the plot I would like to obtain:
x <- seq(1, 20, by=1)
y <- seq(1,40, by=2)
date <- seq(as.Date("2000/1/1"), as.Date("2001/8/1"), by = "month")
# I create a data frame with the date and TWO time series
datframe <- data.frame(date,x,y)
I then would like to plot both series, x and y, with the date on the x axis. I would like the first series displayed with red dotted lines and the second series with a black line, as well as obtaining a legend. This is my ggplot2 code I used so far:
ggplot() + geom_line(data = datframe, aes(x=date, y=datframe$x,group="x"), linetype="dotted", color="red") +
geom_line(data = datframe, aes(x=datframe$date, y=datframe$y, linetype="y"),color = "black")
Well, the problem is that I only have one legend entry and I do not know how to change it. I would really appreciate some hints, I already spent a long time on a simple graph and could not figure it out. I think for you advanced users it might be obvious, sorry for the beginner question but I thank you a lot in advance for any help.