I apologize if this question has been asked already somewhere. I have found some forum posts but with no great solutions for my current situation.
I have the following made-up example data set:
Subject <- c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3) Condition <- c("A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C") Time <- c(1,1,1,2,2,2,1,1,1,2,2,2,1,1,1,2,2,2) Value1 <- c(600,550,450,300,325,250,610,545,453,323,299,280,575,560,475,100,140,85) DF1 <- data.frame (Subject, Condition, Time, Value1)
I have using ggplot to graph this data via line graph with error bars. The goal of this graph is to create an academic publication-ready figure. Therefore, due to the fact that I have large standard deviations (they are even larger in the real data), I would like to only show the upper error bar for the condition with the highest line, and the lower error bar for the conditions with lower lines to try and visually clean this up.
In my example data frame, there is only one
Value however, in reality I have 9 Value variables for each Subject, in each condition, for each time. As a result, I would like to avoid (if possible) manually calculating the mean and SD for each of these combinations.
I am currently using the following ggplot code:
PublicationPlot <-ggplot(DF1, aes(Time, Value1, shape = Condition)) PublicationPlot + stat_summary(fun = mean, geom = "point", size= 2, aes(group = Condition))+ stat_summary(fun= mean, geom = "line", aes(group = Condition, linetype = Condition)) + stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width = 0.075, aes(group = Condition))+ xlab("Measurement Times")+ ylab("Value 1 (Units)")+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line=element_line(color = "black"), legend.key = element_rect(fill= "white"), axis.title.x = element_text(size = 15), axis.text.x = element_text(size = 13), axis.title.y = element_text(size = 15), axis.text.y = element_text(size = 13), legend.title = element_text( size=12), legend.text=element_text(size=12))
Any help on this problem would be incredible. Thank you for your time and expertise. I look forward to learning from you.