I'd like to plot multiple data frames on one plot using ggplot2.
I have about 30 data frames, and each data frame contains the same variables (x=value, y=index, and standard error) like the example below.
e.g.)
df1 <-
value SE index
1 -3.447418 0.4308221 19.00978
2 -3.999097 0.4308221 147.79562
3 -4.316288 0.4308221 268.78998
4 -4.449099 0.4308221 332.87519
5 -3.696987 0.4308221 447.74797
6 -3.313633 0.4308221 565.46903
7 -3.335039 0.4308221 709.58848
8 -2.486115 0.4308221 838.49382
9 -1.230000 0.4308221 993.37466
10 -2.558116 0.4308221 1150.04461
df2
.
.
.
.
.
df30
I want to plot all 30 data frames with different colors with error bars shown for each value. I am new to R and I was barely able to plot a single data frame with an error bar with the following code.
df1 = read.table("data_1.txt", header=TRUE, sep="\t")
p = ggplot(df1, aes(x=index, y=value)) +
geom_line(size=1, colour = "coral") +
geom_point(size=2.5, colour = "coral") +
ylab("value") + xlab("index")
gp = p + scale_y_continuous(limits=c(-5.5, 0.5), breaks=seq(-5.5, 0.5, 0.5)) +
scale_x_continuous(limits=c(0, 1530), breaks=seq(0, 1530, 250)) +
geom_errorbar(aes(ymax=value+sd, ymin=value-sd), width=20, size=0.2, colour = "black") +
theme_classic()
plot(gp)
I have been looking into Displaying multiple data frames in ggplot2 and R : ggplot2 plot several data frames in one plot, but I could not figure out the best solution. Can someone tell me how I would be able to do what I'm looking for?
Thank you very much for your help in advance.