Just coming over from SPSS to R. I have searched this forum and others in search for a solution but cannot make previous solutions work on my material. In my dataframe (mydata) I have about 170 observations over the span of 35 years. There are several variables but for simplicity lets say: I have one variable/column for date of disease onset (named "date") and a grouping variable in one column (named "group") which can take the value of "0" or "1". I have several NAs in the group column. It should also be noted that the row order is not in date order.
Simplified version of how my data looks:
What i want to do is very simple. I want a plot showing the cumulative count of cases over time, one line for each group, NAs excluded. (i.e. Date on the x axis and cumulative count on the y axis)
The closest I have come is this, using ggplot2:
ggplot(mydata,aes(date))+stat_bin(aes(y=cumsum(..count..)),geom="line",bins=30)
I get the kind of plot i want but not with the grouping. How can i solve this?
Update for reproducible example (albeit no NAs)
set.seed(42)
n <- 6
mydata <- data.frame(id=1:n,date=seq.Date(as.Date("2020-12-26"), as.Date("2020-12-31"), "day"),group=rep(1:2:NA, n/2))