1. 程式人生 > >R語言畫點狀誤差線

R語言畫點狀誤差線

網上 img angle 語言 function alt 圖片 擬合 col

現在項目需要R語言做幾個線性擬合,畫一些點圖,突然需要畫誤差線,網上找了下,可以用代碼實現。。效果如下

技術分享圖片

xx1<-c(xxxxxx,xxxx,xxxxx)

yy1<-c(xxxxxx,xxxx,xxxxx)

std1<-c(xxxxxx,xxxx,xxxxx)

std2<-c(xxxxxx,xxxx,xxxxx)

plot_stdy <- function(x, y, sd, len = 1, col = "black") {
len <- len * 0.05
arrows(x0 = x, y0 = y, x1 = x, y1 = y - sd, col = col, angle = 90, length = len)
arrows(x0 = x, y0 = y, x1 = x, y1 = y + sd, col = col, angle = 90, length = len)
}

plot_stdx <- function(x, y, sd, len = 1, col = "black") {
len <- len * 0.05
arrows(x0 = x, y0 = y, x1 = x-sd, y1 =y , col = col, angle = 90,length = len)
arrows(x0 = x, y0 = y, x1 = x+sd, y1 =y, col = col , angle = 90,length = len)
}

plot(xx1,yy1)
plot_stdy(xx1, yy1, sd = std2)

plot_stdx(xx1, yy1, sd = std1)

R語言畫點狀誤差線