【问题标题】:Plotting standard error on radial.plot()在radial.plot() 上绘制标准误差
【发布时间】:2015-10-31 16:53:44
【问题描述】:

我在R 中使用plotrix-packageradial.plot 函数。有谁知道实现标准误差线的简单方法。即使每个径向位置有多个数据点,该解决方案也必须有效,这可能导致SE-bar 部分重叠(见下图)。

现在图表如下所示:

使用代码:

library(plotrix)
ppp <- matrix(runif(1:16, 10, 60), nrow=2, ncol=8)
kl <- c(0, pi/4, pi/2, pi*0.75,pi, pi+pi/4,pi+pi/2, pi+pi*0.75)
plot_rt_soa7 <- radial.plot(ppp,rp.type="p",radial.pos=kl,
                label.pos=kl,start=pi/2,
                labels=1:8,radial.lim=c(-10,65),main="SOA 7")
                legend(45,50,c("T-oben", "T-unten"),col=1:2,lty=1)

错误栏可能看起来像像这样: (来自How to plot error bars in polar coordinates in python?

任何帮助将不胜感激

【问题讨论】:

  • 欢迎来到 SO!请包括reproducible example。这让其他人更容易帮助您。
  • 非常感谢!添加了一个 rep.example 并相应地更改了图片

标签: r plot standard-error plotrix errorbar


【解决方案1】:

下面是一些基本代码,它们将绘制“x”(与半径正交)和“y”(与半径平行)尺寸的误差线,以及中心值的一个点。它不使用plotrix 包绘制误差线,而是使用R 基本图形。您必须提供尺寸的错误或注释掉绘制不需要的错误的代码部分。线宽、颜色、点颜色和点形状有几个图形参数。下面提供了一个示例图表。

library(plotrix)
set.seed(10) # seed for reproducable graph
ppp <- matrix(runif(1:16, 10, 60), nrow=2, ncol=8)
kl <- c(0, pi/4, pi/2, pi*0.75,pi, pi+pi/4,pi+pi/2, pi+pi*0.75)
start <- pi/2 # know starting value for plotting points angularl
rad_low_lim <- -10 # used when computing values of the error lines and in plot limits
plot_rt_soa7 <- radial.plot(ppp,rp.type="p"
                            ,radial.pos=kl
                            ,label.pos=kl
                            ,start=start
                            ,labels=1:8
                            ,radial.lim=c(rad_low_lim,65)
                            ,main="SOA 7")
legend(40,120,c("T-oben", "T-unten"),col=1:2,lty=1)

# generating random error values for both x and y
error_ppp_y <- matrix(rnorm(16, 15, 5), nrow=2, ncol=8)
error_ppp_x <- matrix(rnorm(16, 10, 3), nrow=2, ncol=8)

bar_cols <- c('blue','green') # colors for bars
lwds <- c(4,2) # line weights for bars
pts_cols <- c('black','red') # colors for points
pts_pch <- c(19,17) # point pch

# loop over the number of rows (T-oben and T-unten)
for(j in 1:2){

  # loop over the observations
  for(i in 1:ncol(ppp)){

    # plotting the errors of the 'y' value
    # center value is determined and errors are rotated to make
    # parallel to the radius
    lines(c(ppp[j,i]+error_ppp_y[j,i]-rad_low_lim,ppp[j,i]-error_ppp_y[j,i]-rad_low_lim)*cos(kl[i]+start)
          ,c(ppp[j,i]+error_ppp_y[j,i]-rad_low_lim,ppp[j,i]-error_ppp_y[j,i]-rad_low_lim)*sin(kl[i]+start)
          ,lwd=lwds[j]
          ,col=bar_cols[j]
    )

    # plotting the 'x' errors that are orthognal to the radius
    # points are the "center" with the error values rotated to make them orthognal to the radius
    # comment out if not desired
    lines((ppp[j,i]-rad_low_lim)*cos(kl[i]+start)+c(error_ppp_x[j,i],-error_ppp_x[j,i])*cos(kl[i])
          ,(ppp[j,i]-rad_low_lim)*sin(kl[i]+start)+c(error_ppp_x[j,i],-error_ppp_x[j,i])*sin(kl[i])
          ,lwd=lwds[j]
          ,col=bar_cols[j]
    )

    # plotting points for the center
    # comment out if not desired
    points((ppp[j,i]-rad_low_lim)*cos(kl[i]+start)
          ,(ppp[j,i]-rad_low_lim)*sin(kl[i]+start)
          ,col=pts_cols[j]
          ,pch=pts_pch[j]
    )
  }
}

【讨论】:

  • 难以置信!!非常感谢你。这非常有效。这个网站很棒。我一定会努力为社区做出更多贡献。
  • 如果我的回答足够,请接受它作为您问题的答案。
猜你喜欢
  • 2018-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-27
  • 2011-12-14
  • 2020-12-10
  • 1970-01-01
  • 2013-02-10
相关资源
最近更新 更多