I have two different datasets which I'd like to plot in the same ggplot2 plot, using different geoms for each. Ideally I would also like a legend which shows that the point geom corresponds to one type of data and the line geom corresponds to the other, but I cannot figure out how to do this. An example of what my data basically looks like is below, minus the legend.
require(ggplot2)
set.seed(1)
d1 = data.frame(y_values = rnorm(21), x_values = 1:21, factor_values = as.factor(sample(1:3, 21, replace=T)))
d2 = data.frame(y_values = seq(-1,1,by = .05), x_values = seq(1,21,by = .5))
ggplot() +
geom_point(data=d1, aes(x=x_values, y=y_values, color=factor_values)) +
geom_line(data=d2, aes(x = x_values, y=y_values), color="blue")