如何使用ggplot绘制两列数据框列并且不融化

问题描述

我创建了一个数据框,其中包含一组系数及其标准偏差,如下所示:

      x    co_crowd sd_co_crowd co_not_crowd sd_co_not_crowd
1  0.60  0.43012132   0.1747872    0.3966671       0.1687380
2  0.62  0.46063333   0.1773200    0.3377529       0.1660473
3  0.64  0.46269688   0.1828233    0.3298026       0.1611410
4  0.66  0.40083469   0.1859609    0.3821874       0.1579615
5  0.68  0.35852075   0.1875722    0.3772546       0.1565694
6  0.70  0.28980734   0.1910099    0.4147173       0.1547535
7  0.72  0.33115725   0.1995733    0.3605751       0.1499210
8  0.74  0.37740694   0.2050877    0.3499887       0.1471462
9  0.76  0.33312104   0.2065729    0.3349059       0.1463895
10 0.78  0.33023339   0.2087189    0.3309792       0.1444242
11 0.80  0.20648732   0.2226057    0.4126518       0.1408211
12 0.82  0.08671806   0.2333934    0.5076005       0.1374987
13 0.84  0.09258312   0.2418525    0.4890796       0.1356016
14 0.86  0.08282405   0.2712092    0.4910314       0.1318858
15 0.88  0.05364842   0.2880257    0.5179220       0.1296971
16 0.90 -0.09106470   0.3429453    0.5345661       0.1263504

我想做的是绘制带有错误栏( sd_co_crowd )的 co_crowd 列,以及带有相关错误栏的 co_not_crowd sd_co_not_crowd )以带有点的线形图的形式出现。最初,我编写了以下用于绘图的代码:

plot(x,co_crowd,type="o",col="blue",ylim=c(-0.1,0.7),xlab="",ylab="")
lines(x,co_not_crowd,pch=22,lty=2,col="red",ylab="")


title(main="Coeff results",col.main="red",font.main=4)
legend(0.6,0.1,legend=c("non_crowd","crowd"),col=c("red","blue"),lty=1:2,cex=1.2)
grid(nx = NULL,ny = NULL,col = "lightgray",lty = "dotted")
title(xlab= "Thresholds")  
title(ylab= "Coefficients")  

结果是这种形式:

enter image description here

现在我要在此绘图中添加一个错误栏;但是,我发现的功能是geom_errorbar,用于ggplot,不能在此处使用。因此,为了使用它,我必须使用ggplot。现在我想知道如何绘制两列数据框而不会以线和点的形式融化? (就像我最初绘制的那样)

所以最后,我想要的是这种形式的东西:

enter image description here

通过使用ggplot。 (出于演示目的,我用excel对其进行了绘制)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)