Hey everyone, I have the following problem:
I want to plot ID=1 versus ID=2 in a line diagram with Month on the X-axises and Value on the Y-Axis. It doesn't work in the usual way described below. I think the problem is that I only have 9 observations for ID=2 and 12 for ID=1. One potential solution I came up with is to generate observations, so that I have 3 observations for ID=2 with missing values in the Value column. However, I cannot figure out how to code this. It would be grade to have a continuous line in the plot for ID=1 and a discontinuous line for ID=2, so that I can see for which month the data is missing.
df1 <- data.frame(ID = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2), MONTH = c('MONTH01', 'MONTH02', 'MONTH03', 'MONTH04', 'MONTH05','MONTH06', 'MONTH07','MONTH08','MONTH09','MONTH10','MONTH11','MONTH12', 'MONTH01', 'MONTH02', 'MONTH04','MONTH06', 'MONTH08','MONTH09','MONTH10','MONTH11','MONTH12'), VALUE = c(2,3,3,4,3,3,5,3,3,6,3,3,3,4,5,5,4,3,7,5,3)) #what I tried: library(ggplot2) ggplot(df1, aes(MONTH), geom_line(aes(y=VALUE[ID==1])) + geom_line(aes(y=VALUE[ID==2])))