2016-01-23 91 views
2

由於我的規範性質,我的迴歸係數的結果提供了兩點之間的斜率(產量變化)因此,我想用這兩個點之間的一條線的斜率以第一個點(0, -0.7620)作爲截距繪製這些係數。請注意這是一個編程問題;不是一個統計問題。將變量繪製爲點之間的直線斜率

我不完全確定如何在基本圖形或ggplot中實現這一點,並希望得到任何幫助。以下是一些示例數據。

示例數據:

df <- data.frame(x = c(0, 5, 8, 10, 12, 15, 20, 25, 29), y = c(-0.762,-0.000434, 0.00158, 0.0000822, -0.00294, 0.00246, -0.000521, -0.00009287, -0.01035)) 

輸出:

x   y 
1 0 -7.620e-01 
2 5 -4.340e-04 
3 8 1.580e-03 
4 10 8.220e-05 
5 12 -2.940e-03 
6 15 2.460e-03 
7 20 -5.210e-04 
8 25 -9.287e-05 
9 29 -1.035e-02 

實施例:

enter image description here

+0

是否意味着你要在你的圖九行? – MLavoie

+0

@MLavoie是的,應該有9行 – Vedda

+0

我不確定這是否正確答案,所以請先嚐試它作爲註釋,運行ggplot()+ geom_abline(data = df,aes(intercept = x,slope = y ))+ ylim(0,100)+ xlim(0,100) – MLavoie

回答

2

可以使用cumsum,累計總和,以計算中間值

df <- data.frame(x=c(0, 5, 8, 10, 12, 15, 20, 25, 29),y=cumsum(c(-0.762,-0.000434, 0.00158, 0.0000822, -0.00294, 0.00246, -0.000521, -0.00009287, -0.0103))) 
    plot(df$x,df$y) 

enter image description here