I am trying to compare the durations of different components in a cycle, over several time points (weeks). Ideally, the plot should look like this:
Cycle time with data labels as required
I am able to generate the plot below (code follows), but am unable to add data labels to the chart.
Plot with geom_path() that requires data labels
I plot this from the following:
- df1: cumulative mean durations per week (geom_path() and geom_point() read this)
week variable value
23 Step 1 0.14
24 Step 1 0.21
23 Step 2 0.25
24 Step 2 0.35
23 Step 3 0.53
24 Step 3 0.65
- df2: mean duration per week (data labels come from this)
week variable value
23 Step 1 0.14
24 Step 1 0.21
23 Step 2 0.11
24 Step 2 0.14
23 Step 3 0.28
24 Step 3 0.30
My ggplot code is:
ggplot(df1, aes(x=value, y=week))+
geom_path(mapping=NULL, data=df1,stat="identity", lineend="butt")+
geom_point(aes(colour=variable, size=0.5))+
labs(title="Average cycle time, by components by week",
x="Number of days",
y="Week in the year")+
theme(axis.text=element_text(size=9),
axis.title=element_text(size=12,face="bold"))+
#annotate(geom="text",df2, aes(label=value)),
# hjust=1, vjust=-0.1)
If I try the annotate line, I get a blank plot, with the following error:
Error in is.finite(x) : default method not implemented for type 'list'
I feel it might have something to do with how I specified df1 and df2?
Any thoughts on how to add these data labels?