I have a time series data which has 2 variables (x,y) and I am currently using R base plot to generate a plot like this.
the red lines is a linear model fitted between 2 points.
The data looks likes this.
X
[1] 559.2 559.8 560.6 561.1 561.2 561.8
[7] 562.4 563.0 563.4 563.5 563.5 563.5
[13] 563.5 563.5 563.5 563.5 563.8 564.5
[19] 565.3 565.9 566.4 566.5 566.7 567.4
[25] 567.6 568.5 569.3 570.3 571.6 572.2
[31] 572.5 573.6 574.1 575.5 576.9 578.1
[37] 579.0 580.1 580.9 581.4 581.8 583.1
[43] 583.8 584.4 585.2 586.0 586.1 586.2
[49] 586.8 587.4
**y**
[1] 115.4375 115.3008 115.2069 115.3306 115.3900 115.1189 114.8619
[8] 114.7992 114.7117 114.4722 114.7031 115.1358 115.4811 115.4500
[15] 115.6347 115.8286 115.8361 115.7986 115.9169 116.1225 116.1803
[22] 116.3794 116.2872 116.2517 116.3411 116.4167 116.5108 116.2900
[29] 116.3456 116.3658 116.1547 116.2042 116.1517 116.2083 116.3642
[36] 116.4347 116.5428 116.5119 116.5925 116.3969 116.2614 116.3494
[43] 116.1242 116.1469 116.0872 116.1000 116.2319 116.1225 116.1069
[50] 116.1364
I am calculating the change point manually from X.
Is this kind of plot possible in ggplot2?i.e. using ggplot2 to loop through change points and fit linear model?
Any help would be appreciated. Thanks.