R 向ggplot中散点图上的点添加双向误差条

R 向ggplot中散点图上的点添加双向误差条,r,ggplot2,R,Ggplot2,我试图将x轴和y轴误差条添加到散点图中的每个点。 每个点代表男性和女性健康的标准化平均值(n=33) 我找到了geom_errorbar和geom_errorbarh函数以及这个示例 然而,我的问题是,我想从数据集中的另一列(如下所示)为每个点(我已经计算过)指定标准误差 line MaleBL1 FemaleBL1 BL1MaleSE BL1FemaleSE 3 0.05343516 0.05615977 0.28666600 0.3142001

我试图将x轴和y轴误差条添加到散点图中的每个点。 每个点代表男性和女性健康的标准化平均值(n=33)

我找到了geom_errorbar和geom_errorbarh函数以及这个示例

然而,我的问题是,我想从数据集中的另一列(如下所示)为每个点(我已经计算过)指定标准误差

 line     MaleBL1   FemaleBL1  BL1MaleSE BL1FemaleSE
     3  0.05343516  0.05615977 0.28666600   0.3142001
     4 -0.53321642 -0.27279609 0.23929438   0.1350793
     5 -0.25853484 -0.08283566 0.25904025   0.2984323
     6 -1.11250479  0.03299387 0.23553281   0.2786233
     7 -0.14784506  0.28781883 0.27872358   0.2657080
    10  0.38168220  0.89476555 0.25620796   0.3108585
    11  0.24466921  0.14419021 0.27386482   0.3322349
    12 -0.06119015  1.42294820 0.32903199   0.3632367
    14  0.38957538  1.66850680 0.30362671   0.4437925
    15  0.05784842 -0.12453429 0.32319116   0.3372879
    18  0.71964923 -0.28669563 0.16336556   0.1911489
    23  0.03191843  0.13955703 0.34522310   0.1872229
    28 -0.04598340 -0.35156017 0.27001451   0.1822967
line
”是群体(每个群体中n=10个个体),其中每个值来自我的x,y变量是“
MaleBL1
”和“
FemaleBL1
”,每个群体的标准误差分别为男性和女性“
BL1MaleSE
”和“
BL1FemaleSE

到目前为止,代码方面我有

p<-ggplot(BL1ggplot, aes(x=MaleBL1, y=FemaleBL1)) +
geom_point(shape=1) +    
geom_smooth(method=lm)+ # add regression line
xmin<-(MaleBL1-BL1MaleSE)
xmax<-(MaleBL1+BL1MaleSE)
ymin<-(FemaleBL1-BL1FemaleSE)
ymax<-(FemaleBL1+BL1FemaleSE)    
geom_errorbarh(aes(xmin=xmin,xmax=xmax))+
geom_errorbar(aes(ymin=ymin,ymax=ymax))

p你真的应该学习一些教程。您尚未理解ggplot2语法

BL1ggplot <- read.table(text=" line     MaleBL1   FemaleBL1  BL1MaleSE BL1FemaleSE
     3  0.05343516  0.05615977 0.28666600   0.3142001
     4 -0.53321642 -0.27279609 0.23929438   0.1350793
     5 -0.25853484 -0.08283566 0.25904025   0.2984323
     6 -1.11250479  0.03299387 0.23553281   0.2786233
     7 -0.14784506  0.28781883 0.27872358   0.2657080
    10  0.38168220  0.89476555 0.25620796   0.3108585
    11  0.24466921  0.14419021 0.27386482   0.3322349
    12 -0.06119015  1.42294820 0.32903199   0.3632367
    14  0.38957538  1.66850680 0.30362671   0.4437925
    15  0.05784842 -0.12453429 0.32319116   0.3372879
    18  0.71964923 -0.28669563 0.16336556   0.1911489
    23  0.03191843  0.13955703 0.34522310   0.1872229
    28 -0.04598340 -0.35156017 0.27001451   0.1822967", header=TRUE)

library(ggplot2)
p<-ggplot(BL1ggplot, aes(x=MaleBL1, y=FemaleBL1)) +
  geom_point(shape=1) +    
  geom_smooth(method=lm)+ 
  geom_errorbarh(aes(xmin=MaleBL1-BL1MaleSE,
                   xmax=MaleBL1+BL1MaleSE),
                 height=0.2)+
  geom_errorbar(aes(ymin=FemaleBL1-BL1FemaleSE,
                    ymax=FemaleBL1+BL1FemaleSE),
                width=0.2)

print(p)

BL1ggplot你真的应该学习一些教程。您尚未理解ggplot2语法

BL1ggplot <- read.table(text=" line     MaleBL1   FemaleBL1  BL1MaleSE BL1FemaleSE
     3  0.05343516  0.05615977 0.28666600   0.3142001
     4 -0.53321642 -0.27279609 0.23929438   0.1350793
     5 -0.25853484 -0.08283566 0.25904025   0.2984323
     6 -1.11250479  0.03299387 0.23553281   0.2786233
     7 -0.14784506  0.28781883 0.27872358   0.2657080
    10  0.38168220  0.89476555 0.25620796   0.3108585
    11  0.24466921  0.14419021 0.27386482   0.3322349
    12 -0.06119015  1.42294820 0.32903199   0.3632367
    14  0.38957538  1.66850680 0.30362671   0.4437925
    15  0.05784842 -0.12453429 0.32319116   0.3372879
    18  0.71964923 -0.28669563 0.16336556   0.1911489
    23  0.03191843  0.13955703 0.34522310   0.1872229
    28 -0.04598340 -0.35156017 0.27001451   0.1822967", header=TRUE)

library(ggplot2)
p<-ggplot(BL1ggplot, aes(x=MaleBL1, y=FemaleBL1)) +
  geom_point(shape=1) +    
  geom_smooth(method=lm)+ 
  geom_errorbarh(aes(xmin=MaleBL1-BL1MaleSE,
                   xmax=MaleBL1+BL1MaleSE),
                 height=0.2)+
  geom_errorbar(aes(ymin=FemaleBL1-BL1FemaleSE,
                    ymax=FemaleBL1+BL1FemaleSE),
                width=0.2)

print(p)

BL1ggplot非常感谢您的快速回复。我目前正试图掌握ggplot,但我被要求在匆忙中完成这项工作,但毫无进展。是否有方法将错误条的末端添加到绘图中。我将研究使用其他回归类型。干杯谢谢大家的快速回复。我目前正试图掌握ggplot,但我被要求在匆忙中完成这项工作,但毫无进展。是否有方法将错误条的末端添加到绘图中。我将研究使用其他回归类型。干杯