[英]Plotting standard error on radial.plot()
我在R
中使用plotrix-package
的radial.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)
誤差線可能看起來像這樣:(來自如何在python的極坐標中繪制誤差線? )
任何幫助將非常感激
這是一些基本代碼,這些代碼將繪制“ 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]
)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.