I need to create a ggplot time series chart with one line where the colour of the line depends on a binary factor variable. Somehow my code generates two lines when I colour by factor:
date = seq(as.Date("2018-01-01"), as.Date("2018-01-20"), by = 1)
data = rnorm(20)
factor = as.factor(sample(0:1,20,replace=T))
df = data.frame(date = date, data = data, factor = factor)
p=ggplot(df, aes(date))
p=p + geom_line(aes(y = data, colour = factor))
print(p)
How can I fix the problem?