Plot with two Y axes : confidence intervals

后端 未结 1 1271
春和景丽
春和景丽 2021-01-25 01:56

I am trying to plot several points with error bars, with two y axes. However at every call of the plotCI or errbar functions, a new plot is initialized - with or without par(ne

1条回答
  •  北恋
    北恋 (楼主)
    2021-01-25 02:23

    Use add=TRUE,

    If FALSE (default), create a new plot; if TRUE, add error bars to an existing plot.

    For example the last line becomes:

        plotCI(x,y=y2,uiw=delta,xaxt="n",gap=0,add=TRUE)
    

    screenshot 1

    PS: hard to do this with ggplot2. take a look at this hadley code

    EDIT

    The user coordinate system is now redefined by specifying a new user setting. Here I do it manually.

    plotCI(x,y=y1,uiw=delta,xaxt="n",gap=0)
    axis(side=1,at=c(1:10),labels=rep("a",10),cex=0.7)
    usr <- par("usr")
    par(usr=c(usr[1:2], -1, 20))
    plotCI(x,y=y2,uiw=delta,xaxt="n",gap=0,add=TRUE,col='red')
    axis(4,col.ticks ='red')
    

    screenshot 2

    0 讨论(0)
提交回复
热议问题