I would like to make a graph similar to those graphs here Indicating the statistically significant difference in bar graph
Considering the following example:
library(ggplot2)
# my data
my_data <- data.frame(x = c("No","Yes"), y=c(5,25), lower = c(1,10), upper = c(15,50))
I make a barchart with some errorbars, which works fine.
my_data %>% ggplot(aes(x=withdrawal,y=estimate)) +
geom_bar(stat="identity", fill="grey", width=0.5) +
geom_errorbar(ymin=lower, ymax=upper, width = 0.15) +
coord_cartesian(ylim = c(0,70))
Okay, now I would like to add some annotations with a p-value, which also works fine.
my_data %>% ggplot(aes(x=withdrawal,y=estimate)) +
geom_bar(stat="identity", fill="grey", width=0.5) +
geom_errorbar(ymin=lower, ymax=upper, width = 0.15) +
coord_cartesian(ylim = c(0,70)) +
annotate("text",x=1.5,y=65,label="p<0.001")
Well, but now I would like to add a line indicating the statistically significant difference in bar graph.
my_data %>% ggplot(aes(x=withdrawal,y=estimate)) +
geom_bar(stat="identity", fill="grey", width=0.5) +
geom_errorbar(ymin=lower, ymax=upper, width = 0.15) +
coord_cartesian(ylim = c(0,70)) +
annotate("text",x=1.5,y=65,label="p<0.001") +
geom_path(x=c(1,1,2,2),y=c(55,60,60,55))
Now I did not work. So what is the problem with geom_path? I tried to change the mapping with x.
my_data <- data.frame(x = c(1,2), y=c(5,25), lower = c(1,10), upper = c(15,50))
my_data %>% ggplot(aes(x=withdrawal,y=estimate)) +
geom_bar(stat="identity", fill="grey", width=0.5) +
geom_errorbar(ymin=lower, ymax=upper, width = 0.15) +
coord_cartesian(ylim = c(0,70)) +
annotate("text",x=1.5,y=65,label="p<0.001") +
geom_path(x=c(1,1,2,2),y=c(55,60,60,55))
Still did not work. What may I do to make geom_path work?