【发布时间】:2020-03-17 11:07:52
【问题描述】:
我想使用ggplot2 在一个绘图上绘制多个数据框。
我有大约 30 个数据帧,每个数据帧都包含相同的变量(x=value、y=index 和标准误差),如下例所示。
例如)
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
我想用不同颜色绘制所有 30 个数据框,并为每个值显示误差线。我是 R 新手,我几乎无法使用以下代码绘制带有错误栏的单个数据框。
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)
我一直在研究Displaying multiple data frames in ggplot2 和R : ggplot2 plot several data frames in one plot,但我找不到最佳解决方案。有人可以告诉我如何做我正在寻找的东西吗?
非常感谢您提前提供的帮助。
【问题讨论】: