I am trying to plot a graph of 3 observations (infusion rate, sedation level, tolerance level) as a function of time.
I have data for a hundred patients, which I want to see in separate panels. My data frame has the sedation level and tolerance level data in the same column, "Observation", while the infusion rate is in another column, "Rate". The three observations are grouped by the column "Subtype".
So, far I can plot scatter plot and line with this code:
p <- ggplot(data, aes(group = Subtype, colour = Subtype)) + facet_wrap(~ Pt_ID, ncol = 6) + geom_point(aes(Time, Observation)) + geom_point(aes(Time, Rate), colour = "pink") + geom_line(aes(Time, Rate)) + geom_line(aes(Time, Observation))
However the graph is not what I wanted, I need to get a step plot.
But when I use geom_step function with this code:
p <- ggplot(data, aes(group = Subtype, colour = Subtype)) + facet_wrap(~ Pt_ID, ncol = 6) + geom_step(aes(Time, Observation)) + geom_step(aes(Time, Rate), colour="pink")
I received this error message:
Error in grid.Call.graphics(L_lines, x$x, x$y, index, x$arrow) : invalid line type
I am rather new with R. If anyone can tell me what is wrong with my code or any suggestions, I'd really really appreciate it.