在 r 中绘制三段式回归线
Plotting three-piece regression lines in r
我正在尝试绘制一个三段式回归模型。回归参数在这里:
qdata=data.frame(breakpoint1=1.092201, breakpoint2=6.153361, slope1=1707,
slope2=114.6, slope3=-12.09, intercept1=176.6, intercept2=1916,
intercept3=2696)
数据在这里:
f=structure(list(weight = c(122, 306, 1040, 1498, 1980, 1980, 1983,
2060, 2110, 2180, 2180, 2192.5, 2200, 2219.5, 2230, 2256.5, 2260,
2290, 2300, 2350, 2361, 2370, 2380, 2615, 2724, 1952, 1993, 2029.5,
2088, 2106, 2100, 2100, 2100, 2160, 2170, 2170, 2180, 2180, 2180,
2200, 2220, 2220, 2220, 2220, 2220, 2230, 2230, 2240, 2260, 2270,
2270, 2270, 2280, 2280, 2280, 2280, 2310, 2330, 2340, 2340, 2340,
2340, 2340, 2361, 2370, 2380, 2380, 2380, 2388, 2400, 2400, 2400,
2400, 2410, 2420, 2428.5, 2430, 2460, 2460, 2460, 2460, 2460,
2480, 2480, 2490, 2490, 2500, 2520, 2520, 2530, 2537.5, 2540,
2540, 2540, 2550, 2560, 2574, 2590, 2600, 2620, 2640, 2642, 2660,
2688, 2860, 2906, 27.8, 422.2, 1438.5, 1940, 1960, 1980, 1990,
2000, 2040, 2050, 2070, 2161, 2200, 2210, 673, 1952, 2210, 2210,
2240, 2240, 2290, 2300, 2300, 2300, 2330, 2330, 2340, 2350, 2351,
2360, 2360, 2360, 2390, 2400, 2400, 2420, 2420, 2420, 2420, 2420,
2430, 2440, 2440, 2460, 2470, 2470, 2480, 2480, 2510, 2520, 2520,
2520, 2530, 2550, 2550, 2560, 2560, 2570, 2570, 2580, 2580, 2580,
2590, 2590, 2590, 2600, 2600, 2600, 2610, 2610, 2610, 2610, 2620,
2630, 2640, 2640, 2640, 2640, 2650, 2660, 2669, 2680, 2680, 2710,
2720, 2730, 2740, 2740, 2740, 2760, 2880, 2179, 2361, 2406, 2438,
2583, 2670, 2929, 1960, 1970, 1980, 1980, 1990, 2020, 2080, 2080,
2100, 2100, 2110, 2120, 2120, 2130, 2130, 2130, 2140, 2140, 2150,
2160, 2160, 2170, 2170, 2170, 2175, 2180, 2180, 2180, 2180, 2180,
2180, 2200, 2200, 2200, 2210, 2220, 2230, 2240, 2240, 2260, 2260,
2280, 2280, 2280, 2290, 2300, 2300, 2300, 2300, 2300, 2320, 2320,
2320, 2330, 2340, 2340, 2340, 2340, 2345, 2360, 2360, 2360, 2380,
2380, 2380, 2380, 2380, 2380, 2390, 2395, 2400, 2402, 2420, 2440,
2440, 2440, 2450, 2460, 2480, 2490, 2490, 2500, 2520, 2540, 2550,
2550, 2550, 2555, 2580, 2580, 2585, 2585, 2590, 2600, 2620, 2640,
2683.5, 2730, 2800, 2019.5, 2210, 2240, 2320, 2340, 2390, 2410,
2540, 2550, 2560, 2560, 2576.4, 2640, 2650, 2680, 2700, 2720,
2750, 2760, 2770, 2800, 1099.5, 1943.5, 2050, 2120, 2160, 2170,
2200, 2200, 2200, 2220, 2220, 2230, 2230, 2240, 2240, 2260, 2260,
2261, 2270, 2300, 2320, 2350, 2360, 2360, 2370, 2380, 2380, 2400,
2400, 2410, 2415, 2420, 2420, 2420, 2420, 2440, 2440, 2440, 2440,
2440, 2450, 2450, 2460, 2460, 2460, 2460, 2460, 2460, 2470, 2480,
2480, 2490, 2490, 2500, 2500, 2500, 2520, 2530, 2530, 2537.5,
2540, 2540, 2540, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560,
2580, 2580, 2590, 2600, 2600, 2600, 2600, 2600, 2630, 2640, 2640,
2660, 2680, 2690, 2700, 2700, 2700, 2720, 2720, 2760, 2770, 2780,
2780, 2820, 2860, 2880, 2920, 2930, 2960, 3000, 1126, 2419, 699,
1712, 2646, 1940, 2220, 2320, 2452, 2501.5, 2624, 1680, 1729.5,
1816, 1861, 1897, 2052, 2240, 2240, 2270, 2270, 2300, 2310, 2330,
2340, 2350, 2360, 2360, 2380, 2380, 2390, 2395, 2410, 2420, 2420,
2420, 2420, 2440, 2440, 2460, 2460, 2470, 2470, 2480, 2480, 2480,
2480, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2520, 2520,
2520, 2520, 2530, 2535, 2540, 2540, 2540, 2540, 2540, 2560, 2560,
2560, 2560, 2560, 2570, 2580, 2580, 2580, 2580, 2580, 2580, 2590,
2595, 2600, 2600, 2600, 2600, 2600, 2620, 2620, 2620, 2620, 2630,
2640, 2640, 2640, 2640, 2640, 2650, 2660, 2660, 2660, 2660, 2660,
2670, 2670, 2670, 2680, 2700, 2710, 2720, 2720, 2730, 2740, 2740,
2740, 2740, 2740, 2740, 2760, 2780, 2790, 2800, 2800, 2810, 2810,
2820, 2820, 2830, 2840, 2840, 2850, 2850, 2860, 2860, 2860, 2860,
2880, 2880, 2880, 2880, 2900, 2900, 2920, 2940, 2940, 2940, 2950,
2950, 2960, 2970, 2980, 2980, 2990, 2990, 2990, 2990, 2990, 3000,
3000, 3000, 3030, 171, 2100, 2150, 2160, 2190, 2190, 2210, 2210,
2300, 2320, 2340, 2340, 2360, 2380, 2400, 2410, 2415, 2440, 2440,
2440, 2450, 2450, 2460, 2460, 2460, 2470, 2500, 2500, 2510, 2510,
2520, 2520, 2560, 2570, 2580, 2590, 2600, 2620, 2620, 2620, 2620,
2630, 2633, 2650, 2660, 2670, 2700, 2720, 2720, 2730, 2730, 2730,
2740, 2740, 2740, 2740, 2740, 2760, 2760, 2770, 2780, 2780, 2790,
2800, 2810, 2810, 2810, 2820, 2840, 2840, 2840, 2840, 2860, 2860,
2860, 2870, 2880, 2880, 2900, 2900, 2920, 2920, 2930, 2940, 2960,
2960, 2960, 2970, 2980, 2990, 3010, 229.5, 1916, 2150, 1890,
2101, 2270, 2629, 73, 300, 570, 1340, 1360, 1430, 1660, 1820,
1920, 1940, 1950, 2020, 2020, 2020, 2090, 2150, 2170, 2250, 2310,
2140, 2190, 2260, 2320, 2320, 2360, 2380, 2380, 2420, 2440, 2440,
2480, 2500, 2520, 2520, 2540, 2540, 2550, 2560, 2580, 2580, 2580,
2580, 2580, 2580, 2580, 2600, 2600, 2620, 2660, 2660, 2660, 2660,
2660, 2680, 2680, 2700, 2700, 2700, 2700, 2700, 2700, 2740, 2740,
2740, 2760, 2790, 2880), age = c(0.05, 0.13, 0.39, 0.65, 18.54,
18.62, 13.12, 18.24, 18.52, 16.3, 17.12, 14.61, 18.07, 10.71,
11.36, 13.57, 17.87, 16.72, 17.13, 16.45, 12.5, 14.05, 16.86,
12.99, 11.67, 20.27, 24.7, 23.84, 24.16, 24.02, 11.58, 22.58,
22.59, 11.84, 2.61, 11.96, 12.99, 17.23, 23.12, 23.61, 18.86,
18.88, 22.42, 24.07, 24.15, 22.47, 23.09, 22.54, 19.74, 12.23,
21.85, 22.92, 12.38, 17.93, 21.31, 23.27, 22.75, 12.55, 13.25,
23.81, 23.97, 23.98, 24.27, 8.86, 13.64, 19.63, 21.5, 22.02,
10.11, 15.84, 16.81, 17.77, 23.44, 17.34, 24.42, 8.84, 17.88,
17.67, 19.49, 19.84, 21.14, 21.79, 18.13, 19.13, 14.5, 22.38,
11.19, 16.38, 19.32, 20.97, 7.52, 19.71, 20.22, 20.6, 20.79,
20.02, 9.56, 18.5, 21.68, 14.55, 11.1, 6.38, 15.37, 10.54, 8.35,
8.22, 0, 0.23, 0.78, 13.84, 11.41, 11.57, 13.67, 13.08, 12.14,
13.16, 12.18, 8.54, 11.81, 12.43, 0.19, 0.75, 15.23, 16.3, 22.31,
22.41, 15.48, 22.03, 22.17, 22.21, 16.28, 17.15, 18.33, 9.22,
8.29, 14.35, 22.47, 22.53, 20.75, 17.4, 21.42, 14.13, 15.4, 18.11,
19.07, 19.22, 19.41, 20.76, 21.12, 15.83, 10.62, 12.05, 20.74,
20.96, 13.25, 15.98, 16.88, 17.76, 18.51, 13.64, 15.67, 10.8,
21.88, 16.59, 17.99, 12.44, 17.01, 18.99, 12.93, 13.83, 15.02,
10.99, 17.59, 20.41, 11.68, 12.18, 12.18, 16.19, 11.16, 14.8,
13.09, 14.1, 15.8, 16.8, 18.64, 21.75, 8.51, 18.84, 21.69, 9.47,
14.41, 13.56, 10.4, 11.55, 13.42, 19.83, 20.62, 4.53, 7.55, 2.96,
1.96, 5.57, 7.42, 6.81, 15.17, 20.53, 11.1, 16.53, 15.09, 20.3,
13.43, 15.34, 15.23, 18.36, 7.83, 10.17, 13.39, 11.17, 12.26,
16.28, 8.95, 20.58, 18.27, 19.18, 25.61, 12.46, 14.12, 16.69,
25.37, 16.39, 18.05, 20.12, 22.28, 22.37, 23.28, 19.25, 19.99,
23.4, 18.64, 25.28, 12.21, 18.8, 25.2, 15.81, 25.7, 15.6, 21.11,
21.19, 20.7, 8.27, 16.17, 19.55, 25.56, 25.72, 19.59, 22.58,
23.13, 9, 10.56, 18.88, 18.95, 19.39, 16.02, 16.06, 16.13, 21.39,
12.78, 13.24, 13.28, 13.68, 16.92, 17.88, 16.12, 16.04, 25.03,
5.62, 16.08, 17.55, 20.96, 24.7, 17.31, 19.71, 22.04, 16.02,
21.54, 23.63, 22.93, 24.92, 11.85, 23.95, 24.26, 24.26, 9.67,
22.76, 24.67, 24.69, 15.96, 19.76, 15.93, 21.37, 6.08, 7.43,
24.5, 4.37, 12.3, 11.28, 10.17, 11.47, 10.5, 7.04, 9.9, 12.16,
8.39, 12.91, 3.17, 5.72, 5.87, 5.54, 12.95, 12.05, 8.59, 7.71,
11.72, 10.82, 0.42, 4.58, 5.12, 15.34, 20.52, 7.23, 17.99, 18.27,
21.25, 11.47, 14.41, 6.94, 12.16, 18.08, 23.32, 11.28, 24.55,
3.89, 21.54, 18.18, 15.83, 18.63, 18.53, 23.09, 16.61, 17.45,
24.03, 13.52, 23.9, 7.06, 23.64, 9.48, 15.96, 16.42, 17.22, 9.32,
13.21, 16.25, 23.28, 24.42, 23.41, 23.74, 9.15, 13.19, 16.81,
17.62, 20.7, 24.25, 17.1, 20.13, 23.85, 5.39, 13.98, 23.76, 24.21,
25.41, 12.96, 8.11, 13.84, 1.57, 24.6, 24.95, 25.6, 7.63, 10.16,
20, 22.28, 22.46, 23.61, 24.78, 25.18, 11.72, 25.75, 8.25, 8.99,
13.79, 18.59, 18.84, 18.85, 7.75, 10.85, 25.47, 16.97, 25.34,
21.95, 18.7, 20.81, 22.96, 9.68, 19.79, 9.7, 8.52, 19.62, 22.72,
19.89, 19.47, 18.98, 19.57, 9.63, 19.34, 9.89, 0.52, 1.51, 0.19,
0.94, 2.15, 4.36, 4.76, 2.56, 1.46, 3.01, 3.45, 2.02, 1.76, 2.3,
2.02, 1.76, 2.3, 16.52, 21.34, 4.26, 7.04, 18.24, 12.19, 3.28,
21.28, 16.33, 17.05, 18.08, 8.19, 18.25, 10.43, 24.15, 16.67,
3.05, 9.82, 10.82, 22.32, 3.95, 18.91, 21.25, 24.98, 3.65, 7.18,
16.87, 17.12, 20.19, 22.35, 16.63, 18.85, 21.75, 21.78, 21.96,
22.05, 23.11, 24.21, 16.17, 20.29, 21.65, 24.91, 12.09, 21.58,
17.29, 18.66, 21.43, 21.67, 22.18, 18.53, 21.82, 21.88, 24.83,
25.07, 12.07, 16.42, 20.05, 21.54, 22.88, 23.85, 24.07, 5.48,
24.74, 16.78, 19.52, 22.71, 24.37, 24.49, 19.12, 21.17, 22.53,
23.88, 8, 12.17, 17.53, 17.53, 23.27, 24.66, 20.46, 12.05, 16.92,
17.66, 24.61, 24.74, 11.3, 14.34, 20.65, 17.92, 16.15, 20.87,
19.85, 23.41, 6.36, 10.89, 14.42, 15.99, 17.5, 23.53, 23.68,
5.58, 20.77, 12.39, 15.27, 15.4, 8.67, 11.08, 8.96, 19.68, 6.35,
8.54, 12.11, 4.85, 14.58, 4.56, 5.16, 5.83, 17.82, 8.9, 11.47,
11.64, 15.42, 13.29, 14.07, 11.87, 7.83, 11.94, 15.52, 13.1,
15.92, 15.82, 12.01, 6.62, 13.89, 9.72, 10.72, 12.04, 12.92,
12.93, 7.37, 14.88, 15.02, 12.62, 0.03, 4.41, 15.56, 11.31, 14.35,
14.35, 11.21, 11.24, 15.43, 11.12, 5.32, 14.47, 5.95, 12.05,
13.13, 3.93, 1.57, 4.55, 5.28, 17.35, 5.3, 15.14, 4.53, 10.28,
15.08, 16.36, 11.1, 13.01, 10.91, 11.15, 10.98, 16.5, 10.71,
10.32, 10.11, 3.51, 15.81, 10.87, 11.08, 12.28, 16.06, 6.12,
2.42, 10.1, 13.52, 14.94, 9.44, 6.28, 13.41, 7.77, 11.06, 14.85,
8.98, 9.56, 9.58, 14.12, 17.13, 5.24, 8.13, 2.84, 8.31, 8.48,
9.02, 9.29, 9.52, 9.54, 13.19, 9.21, 4.82, 5.47, 6.89, 8.42,
8.99, 9.19, 9.38, 7.18, 7, 16.78, 9.12, 9.16, 7.94, 9.06, 9.18,
7.64, 5.64, 8.65, 8.82, 8.59, 9.08, 16.96, 9.75, 0.08, 1.35,
2.15, 2.35, 1.33, 2.22, 1.62, 0, 0.12, 0.21, 0.6, 0.87, 0.98,
1.25, 1.4, 3.11, 2.02, 3.53, 2.7, 2.84, 3.59, 1.58, 4.15, 4.32,
3.95, 4.39, 18.45, 18.6, 18.27, 14.04, 18.55, 18.44, 17.92, 18.13,
15.07, 13.2, 17.95, 16.41, 13.03, 13.98, 17.23, 15.05, 15.22,
14.62, 13.86, 12.87, 14.55, 14.65, 16.6, 16.77, 17.59, 17.74,
14.87, 17.17, 17.33, 13.39, 14.23, 15.6, 15.61, 16.12, 15.88,
16.24, 13.89, 13.9, 14.66, 15.81, 16.02, 17.47, 15.71, 15.95,
16.94, 15.43, 15.5, 13.7)), .Names = c("weight", "age"), class = "data.frame", row.names = c(1L,
2L, 3L, 4L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 84L, 85L,
88L, 89L, 90L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L,
114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L,
125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L,
136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L,
147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L,
158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L,
169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L,
180L, 181L, 195L, 196L, 197L, 211L, 212L, 213L, 214L, 215L, 216L,
217L, 218L, 219L, 220L, 221L, 222L, 224L, 225L, 226L, 227L, 228L,
229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L, 239L,
240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L,
251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 260L, 261L,
262L, 263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L, 271L, 272L,
273L, 274L, 275L, 276L, 277L, 278L, 279L, 280L, 281L, 282L, 283L,
284L, 285L, 286L, 287L, 288L, 289L, 290L, 291L, 292L, 293L, 294L,
295L, 296L, 297L, 298L, 299L, 642L, 643L, 644L, 645L, 646L, 647L,
648L, 657L, 658L, 659L, 660L, 661L, 662L, 665L, 666L, 667L, 668L,
670L, 671L, 672L, 674L, 675L, 676L, 677L, 678L, 680L, 681L, 682L,
683L, 684L, 685L, 686L, 687L, 688L, 689L, 690L, 691L, 692L, 694L,
695L, 696L, 699L, 700L, 704L, 705L, 706L, 709L, 710L, 715L, 716L,
717L, 720L, 721L, 722L, 723L, 724L, 725L, 727L, 728L, 729L, 730L,
731L, 732L, 733L, 734L, 736L, 737L, 738L, 739L, 740L, 741L, 742L,
743L, 744L, 745L, 747L, 748L, 749L, 750L, 751L, 752L, 753L, 754L,
755L, 756L, 757L, 758L, 759L, 760L, 761L, 762L, 763L, 764L, 765L,
766L, 767L, 768L, 769L, 770L, 771L, 772L, 773L, 774L, 775L, 776L,
777L, 867L, 868L, 869L, 870L, 871L, 872L, 873L, 874L, 875L, 876L,
877L, 878L, 879L, 880L, 881L, 882L, 883L, 884L, 885L, 886L, 887L,
893L, 894L, 895L, 896L, 897L, 898L, 899L, 900L, 901L, 902L, 903L,
904L, 905L, 906L, 907L, 908L, 909L, 911L, 912L, 913L, 914L, 916L,
917L, 918L, 920L, 921L, 922L, 923L, 924L, 926L, 927L, 928L, 929L,
930L, 931L, 933L, 934L, 935L, 936L, 937L, 938L, 939L, 940L, 941L,
942L, 943L, 944L, 945L, 948L, 949L, 950L, 951L, 952L, 953L, 954L,
955L, 957L, 958L, 959L, 960L, 961L, 962L, 963L, 964L, 965L, 966L,
967L, 968L, 969L, 970L, 971L, 972L, 973L, 974L, 975L, 976L, 977L,
978L, 979L, 982L, 983L, 984L, 985L, 986L, 987L, 988L, 989L, 990L,
993L, 994L, 996L, 998L, 999L, 1000L, 1001L, 1002L, 1003L, 1004L,
1005L, 1006L, 1007L, 1137L, 1138L, 1139L, 1141L, 1142L, 1286L,
1287L, 1288L, 1289L, 1290L, 1291L, 1292L, 1293L, 1294L, 1295L,
1296L, 1297L, 1312L, 1313L, 1314L, 1315L, 1316L, 1317L, 1318L,
1319L, 1320L, 1321L, 1322L, 1323L, 1324L, 1325L, 1326L, 1327L,
1328L, 1329L, 1330L, 1331L, 1332L, 1333L, 1334L, 1335L, 1336L,
1337L, 1338L, 1339L, 1340L, 1341L, 1342L, 1343L, 1344L, 1345L,
1346L, 1347L, 1348L, 1349L, 1350L, 1351L, 1352L, 1353L, 1354L,
1355L, 1356L, 1357L, 1358L, 1359L, 1360L, 1361L, 1362L, 1363L,
1364L, 1365L, 1366L, 1367L, 1368L, 1369L, 1370L, 1371L, 1372L,
1373L, 1374L, 1375L, 1376L, 1377L, 1378L, 1379L, 1380L, 1381L,
1382L, 1383L, 1384L, 1385L, 1386L, 1387L, 1388L, 1389L, 1390L,
1391L, 1392L, 1393L, 1394L, 1395L, 1396L, 1397L, 1398L, 1399L,
1400L, 1401L, 1402L, 1403L, 1404L, 1405L, 1406L, 1407L, 1408L,
1409L, 1410L, 1411L, 1413L, 1414L, 1415L, 1416L, 1417L, 1418L,
1419L, 1420L, 1421L, 1422L, 1423L, 1424L, 1425L, 1426L, 1427L,
1428L, 1429L, 1430L, 1431L, 1432L, 1433L, 1434L, 1435L, 1436L,
1437L, 1438L, 1439L, 1440L, 1441L, 1442L, 1443L, 1444L, 1445L,
1446L, 1447L, 1448L, 1449L, 1450L, 1451L, 1452L, 1453L, 1454L,
1481L, 1482L, 1483L, 1484L, 1485L, 1486L, 1487L, 1488L, 1489L,
1490L, 1491L, 1492L, 1493L, 1494L, 1495L, 1496L, 1497L, 1498L,
1499L, 1500L, 1501L, 1502L, 1503L, 1504L, 1505L, 1506L, 1507L,
1508L, 1509L, 1510L, 1511L, 1512L, 1513L, 1514L, 1515L, 1516L,
1517L, 1518L, 1519L, 1520L, 1521L, 1522L, 1523L, 1524L, 1525L,
1526L, 1527L, 1528L, 1529L, 1530L, 1531L, 1532L, 1533L, 1534L,
1535L, 1536L, 1537L, 1538L, 1539L, 1540L, 1541L, 1542L, 1543L,
1544L, 1545L, 1546L, 1547L, 1548L, 1550L, 1551L, 1552L, 1553L,
1554L, 1555L, 1556L, 1557L, 1558L, 1559L, 1560L, 1561L, 1562L,
1563L, 1564L, 1565L, 1566L, 1567L, 1568L, 1569L, 1570L, 1571L,
1572L, 1574L, 1575L, 1576L, 1577L, 1578L, 1579L, 1580L, 1779L,
1780L, 1781L, 1782L, 1783L, 1784L, 1785L, 1786L, 1787L, 1788L,
1789L, 1790L, 1791L, 1792L, 1793L, 1794L, 1795L, 1796L, 1797L,
2058L, 2059L, 2060L, 2061L, 2062L, 2063L, 2064L, 2065L, 2066L,
2067L, 2068L, 2069L, 2070L, 2071L, 2072L, 2073L, 2074L, 2075L,
2076L, 2077L, 2078L, 2079L, 2080L, 2081L, 2082L, 2083L, 2084L,
2085L, 2086L, 2087L, 2088L, 2089L, 2090L, 2091L, 2092L, 2093L,
2094L, 2095L, 2096L, 2097L, 2098L, 2099L, 2100L, 2101L, 2102L,
2103L, 2104L, 2105L))
我可以使用以下代码绘制三条线:
plot(f$age,f$weight)
curve(qdata$intercept1 + qdata$slope1*x, add=T, from=0, to=qdata$breakpoint1, col=2)
curve(qdata$intercept2 + qdata$slope2*x, add=T, from=qdata$breakpoint1, to=qdata$breakpoint2, col=2)
curve(qdata$intercept3 + qdata$slope3*x, add=T, from=qdata$breakpoint2, to=max(f$age), col=2)
出于我的目的,第三段的斜率没有生物学意义,因此为了呈现数据,我想将第三段的斜率设置为零:
plot(f$age,f$weight)
curve(qdata$intercept1 + qdata$slope1*x, add=T, from=0, to=qdata$breakpoint1, col=2)
curve(qdata$intercept2 + qdata$slope2*x, add=T, from=qdata$breakpoint1, to=qdata$breakpoint2, col=2)
curve(qdata$intercept3 + 0*x, add=T, from=qdata$intecept3, to=max(f$age), col=2)
但是,当我这样做时,我在第二条线段的末尾和第三条线段的开头之间出现了间隙。我想知道是否有人知道如何在将第三条线的斜率设置为零的同时保持第二条和第三条线的连接。
您提供的代码有两个问题。要使趋势线在 x-axis 上的正确位置开始,您只需修复我认为是代码中的拼写错误:
curve(qdata$intercept3 + 0*x, add=T, from=qdata$intecept3, to=max(f$age), col=2)
应该写成:
curve(qdata$intercept3 + 0*x, add=T, from=qdata$breakpoint2, to=max(f$age), col=2)
y-axis 上不连续的原因稍微复杂一些,但仍然很容易修复。原始线与第二条线的末端完美连接,因为它从 y-intercept 开始并略微向下趋势。当您将斜率重置为 0 时,新线将投射到所需点上方。因此,要绘制所需的线,您需要 re-calculate y 截距,这将产生一条穿过第二条趋势线末端的平线:
qdata$fake.intercept <- qdata$intercept2 + qdata$slope2 * qdata$breakpoint2
curve(qdata$fake.intercept + 0 * x, add = T, from = qdata$breakpoint2, to = max(f$age), col = 2)
这应该会产生下图,我相信这就是您想要的:
我正在尝试绘制一个三段式回归模型。回归参数在这里:
qdata=data.frame(breakpoint1=1.092201, breakpoint2=6.153361, slope1=1707,
slope2=114.6, slope3=-12.09, intercept1=176.6, intercept2=1916,
intercept3=2696)
数据在这里:
f=structure(list(weight = c(122, 306, 1040, 1498, 1980, 1980, 1983,
2060, 2110, 2180, 2180, 2192.5, 2200, 2219.5, 2230, 2256.5, 2260,
2290, 2300, 2350, 2361, 2370, 2380, 2615, 2724, 1952, 1993, 2029.5,
2088, 2106, 2100, 2100, 2100, 2160, 2170, 2170, 2180, 2180, 2180,
2200, 2220, 2220, 2220, 2220, 2220, 2230, 2230, 2240, 2260, 2270,
2270, 2270, 2280, 2280, 2280, 2280, 2310, 2330, 2340, 2340, 2340,
2340, 2340, 2361, 2370, 2380, 2380, 2380, 2388, 2400, 2400, 2400,
2400, 2410, 2420, 2428.5, 2430, 2460, 2460, 2460, 2460, 2460,
2480, 2480, 2490, 2490, 2500, 2520, 2520, 2530, 2537.5, 2540,
2540, 2540, 2550, 2560, 2574, 2590, 2600, 2620, 2640, 2642, 2660,
2688, 2860, 2906, 27.8, 422.2, 1438.5, 1940, 1960, 1980, 1990,
2000, 2040, 2050, 2070, 2161, 2200, 2210, 673, 1952, 2210, 2210,
2240, 2240, 2290, 2300, 2300, 2300, 2330, 2330, 2340, 2350, 2351,
2360, 2360, 2360, 2390, 2400, 2400, 2420, 2420, 2420, 2420, 2420,
2430, 2440, 2440, 2460, 2470, 2470, 2480, 2480, 2510, 2520, 2520,
2520, 2530, 2550, 2550, 2560, 2560, 2570, 2570, 2580, 2580, 2580,
2590, 2590, 2590, 2600, 2600, 2600, 2610, 2610, 2610, 2610, 2620,
2630, 2640, 2640, 2640, 2640, 2650, 2660, 2669, 2680, 2680, 2710,
2720, 2730, 2740, 2740, 2740, 2760, 2880, 2179, 2361, 2406, 2438,
2583, 2670, 2929, 1960, 1970, 1980, 1980, 1990, 2020, 2080, 2080,
2100, 2100, 2110, 2120, 2120, 2130, 2130, 2130, 2140, 2140, 2150,
2160, 2160, 2170, 2170, 2170, 2175, 2180, 2180, 2180, 2180, 2180,
2180, 2200, 2200, 2200, 2210, 2220, 2230, 2240, 2240, 2260, 2260,
2280, 2280, 2280, 2290, 2300, 2300, 2300, 2300, 2300, 2320, 2320,
2320, 2330, 2340, 2340, 2340, 2340, 2345, 2360, 2360, 2360, 2380,
2380, 2380, 2380, 2380, 2380, 2390, 2395, 2400, 2402, 2420, 2440,
2440, 2440, 2450, 2460, 2480, 2490, 2490, 2500, 2520, 2540, 2550,
2550, 2550, 2555, 2580, 2580, 2585, 2585, 2590, 2600, 2620, 2640,
2683.5, 2730, 2800, 2019.5, 2210, 2240, 2320, 2340, 2390, 2410,
2540, 2550, 2560, 2560, 2576.4, 2640, 2650, 2680, 2700, 2720,
2750, 2760, 2770, 2800, 1099.5, 1943.5, 2050, 2120, 2160, 2170,
2200, 2200, 2200, 2220, 2220, 2230, 2230, 2240, 2240, 2260, 2260,
2261, 2270, 2300, 2320, 2350, 2360, 2360, 2370, 2380, 2380, 2400,
2400, 2410, 2415, 2420, 2420, 2420, 2420, 2440, 2440, 2440, 2440,
2440, 2450, 2450, 2460, 2460, 2460, 2460, 2460, 2460, 2470, 2480,
2480, 2490, 2490, 2500, 2500, 2500, 2520, 2530, 2530, 2537.5,
2540, 2540, 2540, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560,
2580, 2580, 2590, 2600, 2600, 2600, 2600, 2600, 2630, 2640, 2640,
2660, 2680, 2690, 2700, 2700, 2700, 2720, 2720, 2760, 2770, 2780,
2780, 2820, 2860, 2880, 2920, 2930, 2960, 3000, 1126, 2419, 699,
1712, 2646, 1940, 2220, 2320, 2452, 2501.5, 2624, 1680, 1729.5,
1816, 1861, 1897, 2052, 2240, 2240, 2270, 2270, 2300, 2310, 2330,
2340, 2350, 2360, 2360, 2380, 2380, 2390, 2395, 2410, 2420, 2420,
2420, 2420, 2440, 2440, 2460, 2460, 2470, 2470, 2480, 2480, 2480,
2480, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2520, 2520,
2520, 2520, 2530, 2535, 2540, 2540, 2540, 2540, 2540, 2560, 2560,
2560, 2560, 2560, 2570, 2580, 2580, 2580, 2580, 2580, 2580, 2590,
2595, 2600, 2600, 2600, 2600, 2600, 2620, 2620, 2620, 2620, 2630,
2640, 2640, 2640, 2640, 2640, 2650, 2660, 2660, 2660, 2660, 2660,
2670, 2670, 2670, 2680, 2700, 2710, 2720, 2720, 2730, 2740, 2740,
2740, 2740, 2740, 2740, 2760, 2780, 2790, 2800, 2800, 2810, 2810,
2820, 2820, 2830, 2840, 2840, 2850, 2850, 2860, 2860, 2860, 2860,
2880, 2880, 2880, 2880, 2900, 2900, 2920, 2940, 2940, 2940, 2950,
2950, 2960, 2970, 2980, 2980, 2990, 2990, 2990, 2990, 2990, 3000,
3000, 3000, 3030, 171, 2100, 2150, 2160, 2190, 2190, 2210, 2210,
2300, 2320, 2340, 2340, 2360, 2380, 2400, 2410, 2415, 2440, 2440,
2440, 2450, 2450, 2460, 2460, 2460, 2470, 2500, 2500, 2510, 2510,
2520, 2520, 2560, 2570, 2580, 2590, 2600, 2620, 2620, 2620, 2620,
2630, 2633, 2650, 2660, 2670, 2700, 2720, 2720, 2730, 2730, 2730,
2740, 2740, 2740, 2740, 2740, 2760, 2760, 2770, 2780, 2780, 2790,
2800, 2810, 2810, 2810, 2820, 2840, 2840, 2840, 2840, 2860, 2860,
2860, 2870, 2880, 2880, 2900, 2900, 2920, 2920, 2930, 2940, 2960,
2960, 2960, 2970, 2980, 2990, 3010, 229.5, 1916, 2150, 1890,
2101, 2270, 2629, 73, 300, 570, 1340, 1360, 1430, 1660, 1820,
1920, 1940, 1950, 2020, 2020, 2020, 2090, 2150, 2170, 2250, 2310,
2140, 2190, 2260, 2320, 2320, 2360, 2380, 2380, 2420, 2440, 2440,
2480, 2500, 2520, 2520, 2540, 2540, 2550, 2560, 2580, 2580, 2580,
2580, 2580, 2580, 2580, 2600, 2600, 2620, 2660, 2660, 2660, 2660,
2660, 2680, 2680, 2700, 2700, 2700, 2700, 2700, 2700, 2740, 2740,
2740, 2760, 2790, 2880), age = c(0.05, 0.13, 0.39, 0.65, 18.54,
18.62, 13.12, 18.24, 18.52, 16.3, 17.12, 14.61, 18.07, 10.71,
11.36, 13.57, 17.87, 16.72, 17.13, 16.45, 12.5, 14.05, 16.86,
12.99, 11.67, 20.27, 24.7, 23.84, 24.16, 24.02, 11.58, 22.58,
22.59, 11.84, 2.61, 11.96, 12.99, 17.23, 23.12, 23.61, 18.86,
18.88, 22.42, 24.07, 24.15, 22.47, 23.09, 22.54, 19.74, 12.23,
21.85, 22.92, 12.38, 17.93, 21.31, 23.27, 22.75, 12.55, 13.25,
23.81, 23.97, 23.98, 24.27, 8.86, 13.64, 19.63, 21.5, 22.02,
10.11, 15.84, 16.81, 17.77, 23.44, 17.34, 24.42, 8.84, 17.88,
17.67, 19.49, 19.84, 21.14, 21.79, 18.13, 19.13, 14.5, 22.38,
11.19, 16.38, 19.32, 20.97, 7.52, 19.71, 20.22, 20.6, 20.79,
20.02, 9.56, 18.5, 21.68, 14.55, 11.1, 6.38, 15.37, 10.54, 8.35,
8.22, 0, 0.23, 0.78, 13.84, 11.41, 11.57, 13.67, 13.08, 12.14,
13.16, 12.18, 8.54, 11.81, 12.43, 0.19, 0.75, 15.23, 16.3, 22.31,
22.41, 15.48, 22.03, 22.17, 22.21, 16.28, 17.15, 18.33, 9.22,
8.29, 14.35, 22.47, 22.53, 20.75, 17.4, 21.42, 14.13, 15.4, 18.11,
19.07, 19.22, 19.41, 20.76, 21.12, 15.83, 10.62, 12.05, 20.74,
20.96, 13.25, 15.98, 16.88, 17.76, 18.51, 13.64, 15.67, 10.8,
21.88, 16.59, 17.99, 12.44, 17.01, 18.99, 12.93, 13.83, 15.02,
10.99, 17.59, 20.41, 11.68, 12.18, 12.18, 16.19, 11.16, 14.8,
13.09, 14.1, 15.8, 16.8, 18.64, 21.75, 8.51, 18.84, 21.69, 9.47,
14.41, 13.56, 10.4, 11.55, 13.42, 19.83, 20.62, 4.53, 7.55, 2.96,
1.96, 5.57, 7.42, 6.81, 15.17, 20.53, 11.1, 16.53, 15.09, 20.3,
13.43, 15.34, 15.23, 18.36, 7.83, 10.17, 13.39, 11.17, 12.26,
16.28, 8.95, 20.58, 18.27, 19.18, 25.61, 12.46, 14.12, 16.69,
25.37, 16.39, 18.05, 20.12, 22.28, 22.37, 23.28, 19.25, 19.99,
23.4, 18.64, 25.28, 12.21, 18.8, 25.2, 15.81, 25.7, 15.6, 21.11,
21.19, 20.7, 8.27, 16.17, 19.55, 25.56, 25.72, 19.59, 22.58,
23.13, 9, 10.56, 18.88, 18.95, 19.39, 16.02, 16.06, 16.13, 21.39,
12.78, 13.24, 13.28, 13.68, 16.92, 17.88, 16.12, 16.04, 25.03,
5.62, 16.08, 17.55, 20.96, 24.7, 17.31, 19.71, 22.04, 16.02,
21.54, 23.63, 22.93, 24.92, 11.85, 23.95, 24.26, 24.26, 9.67,
22.76, 24.67, 24.69, 15.96, 19.76, 15.93, 21.37, 6.08, 7.43,
24.5, 4.37, 12.3, 11.28, 10.17, 11.47, 10.5, 7.04, 9.9, 12.16,
8.39, 12.91, 3.17, 5.72, 5.87, 5.54, 12.95, 12.05, 8.59, 7.71,
11.72, 10.82, 0.42, 4.58, 5.12, 15.34, 20.52, 7.23, 17.99, 18.27,
21.25, 11.47, 14.41, 6.94, 12.16, 18.08, 23.32, 11.28, 24.55,
3.89, 21.54, 18.18, 15.83, 18.63, 18.53, 23.09, 16.61, 17.45,
24.03, 13.52, 23.9, 7.06, 23.64, 9.48, 15.96, 16.42, 17.22, 9.32,
13.21, 16.25, 23.28, 24.42, 23.41, 23.74, 9.15, 13.19, 16.81,
17.62, 20.7, 24.25, 17.1, 20.13, 23.85, 5.39, 13.98, 23.76, 24.21,
25.41, 12.96, 8.11, 13.84, 1.57, 24.6, 24.95, 25.6, 7.63, 10.16,
20, 22.28, 22.46, 23.61, 24.78, 25.18, 11.72, 25.75, 8.25, 8.99,
13.79, 18.59, 18.84, 18.85, 7.75, 10.85, 25.47, 16.97, 25.34,
21.95, 18.7, 20.81, 22.96, 9.68, 19.79, 9.7, 8.52, 19.62, 22.72,
19.89, 19.47, 18.98, 19.57, 9.63, 19.34, 9.89, 0.52, 1.51, 0.19,
0.94, 2.15, 4.36, 4.76, 2.56, 1.46, 3.01, 3.45, 2.02, 1.76, 2.3,
2.02, 1.76, 2.3, 16.52, 21.34, 4.26, 7.04, 18.24, 12.19, 3.28,
21.28, 16.33, 17.05, 18.08, 8.19, 18.25, 10.43, 24.15, 16.67,
3.05, 9.82, 10.82, 22.32, 3.95, 18.91, 21.25, 24.98, 3.65, 7.18,
16.87, 17.12, 20.19, 22.35, 16.63, 18.85, 21.75, 21.78, 21.96,
22.05, 23.11, 24.21, 16.17, 20.29, 21.65, 24.91, 12.09, 21.58,
17.29, 18.66, 21.43, 21.67, 22.18, 18.53, 21.82, 21.88, 24.83,
25.07, 12.07, 16.42, 20.05, 21.54, 22.88, 23.85, 24.07, 5.48,
24.74, 16.78, 19.52, 22.71, 24.37, 24.49, 19.12, 21.17, 22.53,
23.88, 8, 12.17, 17.53, 17.53, 23.27, 24.66, 20.46, 12.05, 16.92,
17.66, 24.61, 24.74, 11.3, 14.34, 20.65, 17.92, 16.15, 20.87,
19.85, 23.41, 6.36, 10.89, 14.42, 15.99, 17.5, 23.53, 23.68,
5.58, 20.77, 12.39, 15.27, 15.4, 8.67, 11.08, 8.96, 19.68, 6.35,
8.54, 12.11, 4.85, 14.58, 4.56, 5.16, 5.83, 17.82, 8.9, 11.47,
11.64, 15.42, 13.29, 14.07, 11.87, 7.83, 11.94, 15.52, 13.1,
15.92, 15.82, 12.01, 6.62, 13.89, 9.72, 10.72, 12.04, 12.92,
12.93, 7.37, 14.88, 15.02, 12.62, 0.03, 4.41, 15.56, 11.31, 14.35,
14.35, 11.21, 11.24, 15.43, 11.12, 5.32, 14.47, 5.95, 12.05,
13.13, 3.93, 1.57, 4.55, 5.28, 17.35, 5.3, 15.14, 4.53, 10.28,
15.08, 16.36, 11.1, 13.01, 10.91, 11.15, 10.98, 16.5, 10.71,
10.32, 10.11, 3.51, 15.81, 10.87, 11.08, 12.28, 16.06, 6.12,
2.42, 10.1, 13.52, 14.94, 9.44, 6.28, 13.41, 7.77, 11.06, 14.85,
8.98, 9.56, 9.58, 14.12, 17.13, 5.24, 8.13, 2.84, 8.31, 8.48,
9.02, 9.29, 9.52, 9.54, 13.19, 9.21, 4.82, 5.47, 6.89, 8.42,
8.99, 9.19, 9.38, 7.18, 7, 16.78, 9.12, 9.16, 7.94, 9.06, 9.18,
7.64, 5.64, 8.65, 8.82, 8.59, 9.08, 16.96, 9.75, 0.08, 1.35,
2.15, 2.35, 1.33, 2.22, 1.62, 0, 0.12, 0.21, 0.6, 0.87, 0.98,
1.25, 1.4, 3.11, 2.02, 3.53, 2.7, 2.84, 3.59, 1.58, 4.15, 4.32,
3.95, 4.39, 18.45, 18.6, 18.27, 14.04, 18.55, 18.44, 17.92, 18.13,
15.07, 13.2, 17.95, 16.41, 13.03, 13.98, 17.23, 15.05, 15.22,
14.62, 13.86, 12.87, 14.55, 14.65, 16.6, 16.77, 17.59, 17.74,
14.87, 17.17, 17.33, 13.39, 14.23, 15.6, 15.61, 16.12, 15.88,
16.24, 13.89, 13.9, 14.66, 15.81, 16.02, 17.47, 15.71, 15.95,
16.94, 15.43, 15.5, 13.7)), .Names = c("weight", "age"), class = "data.frame", row.names = c(1L,
2L, 3L, 4L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 84L, 85L,
88L, 89L, 90L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L,
114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L,
125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L,
136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L,
147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L,
158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L,
169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L,
180L, 181L, 195L, 196L, 197L, 211L, 212L, 213L, 214L, 215L, 216L,
217L, 218L, 219L, 220L, 221L, 222L, 224L, 225L, 226L, 227L, 228L,
229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L, 239L,
240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L,
251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 260L, 261L,
262L, 263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L, 271L, 272L,
273L, 274L, 275L, 276L, 277L, 278L, 279L, 280L, 281L, 282L, 283L,
284L, 285L, 286L, 287L, 288L, 289L, 290L, 291L, 292L, 293L, 294L,
295L, 296L, 297L, 298L, 299L, 642L, 643L, 644L, 645L, 646L, 647L,
648L, 657L, 658L, 659L, 660L, 661L, 662L, 665L, 666L, 667L, 668L,
670L, 671L, 672L, 674L, 675L, 676L, 677L, 678L, 680L, 681L, 682L,
683L, 684L, 685L, 686L, 687L, 688L, 689L, 690L, 691L, 692L, 694L,
695L, 696L, 699L, 700L, 704L, 705L, 706L, 709L, 710L, 715L, 716L,
717L, 720L, 721L, 722L, 723L, 724L, 725L, 727L, 728L, 729L, 730L,
731L, 732L, 733L, 734L, 736L, 737L, 738L, 739L, 740L, 741L, 742L,
743L, 744L, 745L, 747L, 748L, 749L, 750L, 751L, 752L, 753L, 754L,
755L, 756L, 757L, 758L, 759L, 760L, 761L, 762L, 763L, 764L, 765L,
766L, 767L, 768L, 769L, 770L, 771L, 772L, 773L, 774L, 775L, 776L,
777L, 867L, 868L, 869L, 870L, 871L, 872L, 873L, 874L, 875L, 876L,
877L, 878L, 879L, 880L, 881L, 882L, 883L, 884L, 885L, 886L, 887L,
893L, 894L, 895L, 896L, 897L, 898L, 899L, 900L, 901L, 902L, 903L,
904L, 905L, 906L, 907L, 908L, 909L, 911L, 912L, 913L, 914L, 916L,
917L, 918L, 920L, 921L, 922L, 923L, 924L, 926L, 927L, 928L, 929L,
930L, 931L, 933L, 934L, 935L, 936L, 937L, 938L, 939L, 940L, 941L,
942L, 943L, 944L, 945L, 948L, 949L, 950L, 951L, 952L, 953L, 954L,
955L, 957L, 958L, 959L, 960L, 961L, 962L, 963L, 964L, 965L, 966L,
967L, 968L, 969L, 970L, 971L, 972L, 973L, 974L, 975L, 976L, 977L,
978L, 979L, 982L, 983L, 984L, 985L, 986L, 987L, 988L, 989L, 990L,
993L, 994L, 996L, 998L, 999L, 1000L, 1001L, 1002L, 1003L, 1004L,
1005L, 1006L, 1007L, 1137L, 1138L, 1139L, 1141L, 1142L, 1286L,
1287L, 1288L, 1289L, 1290L, 1291L, 1292L, 1293L, 1294L, 1295L,
1296L, 1297L, 1312L, 1313L, 1314L, 1315L, 1316L, 1317L, 1318L,
1319L, 1320L, 1321L, 1322L, 1323L, 1324L, 1325L, 1326L, 1327L,
1328L, 1329L, 1330L, 1331L, 1332L, 1333L, 1334L, 1335L, 1336L,
1337L, 1338L, 1339L, 1340L, 1341L, 1342L, 1343L, 1344L, 1345L,
1346L, 1347L, 1348L, 1349L, 1350L, 1351L, 1352L, 1353L, 1354L,
1355L, 1356L, 1357L, 1358L, 1359L, 1360L, 1361L, 1362L, 1363L,
1364L, 1365L, 1366L, 1367L, 1368L, 1369L, 1370L, 1371L, 1372L,
1373L, 1374L, 1375L, 1376L, 1377L, 1378L, 1379L, 1380L, 1381L,
1382L, 1383L, 1384L, 1385L, 1386L, 1387L, 1388L, 1389L, 1390L,
1391L, 1392L, 1393L, 1394L, 1395L, 1396L, 1397L, 1398L, 1399L,
1400L, 1401L, 1402L, 1403L, 1404L, 1405L, 1406L, 1407L, 1408L,
1409L, 1410L, 1411L, 1413L, 1414L, 1415L, 1416L, 1417L, 1418L,
1419L, 1420L, 1421L, 1422L, 1423L, 1424L, 1425L, 1426L, 1427L,
1428L, 1429L, 1430L, 1431L, 1432L, 1433L, 1434L, 1435L, 1436L,
1437L, 1438L, 1439L, 1440L, 1441L, 1442L, 1443L, 1444L, 1445L,
1446L, 1447L, 1448L, 1449L, 1450L, 1451L, 1452L, 1453L, 1454L,
1481L, 1482L, 1483L, 1484L, 1485L, 1486L, 1487L, 1488L, 1489L,
1490L, 1491L, 1492L, 1493L, 1494L, 1495L, 1496L, 1497L, 1498L,
1499L, 1500L, 1501L, 1502L, 1503L, 1504L, 1505L, 1506L, 1507L,
1508L, 1509L, 1510L, 1511L, 1512L, 1513L, 1514L, 1515L, 1516L,
1517L, 1518L, 1519L, 1520L, 1521L, 1522L, 1523L, 1524L, 1525L,
1526L, 1527L, 1528L, 1529L, 1530L, 1531L, 1532L, 1533L, 1534L,
1535L, 1536L, 1537L, 1538L, 1539L, 1540L, 1541L, 1542L, 1543L,
1544L, 1545L, 1546L, 1547L, 1548L, 1550L, 1551L, 1552L, 1553L,
1554L, 1555L, 1556L, 1557L, 1558L, 1559L, 1560L, 1561L, 1562L,
1563L, 1564L, 1565L, 1566L, 1567L, 1568L, 1569L, 1570L, 1571L,
1572L, 1574L, 1575L, 1576L, 1577L, 1578L, 1579L, 1580L, 1779L,
1780L, 1781L, 1782L, 1783L, 1784L, 1785L, 1786L, 1787L, 1788L,
1789L, 1790L, 1791L, 1792L, 1793L, 1794L, 1795L, 1796L, 1797L,
2058L, 2059L, 2060L, 2061L, 2062L, 2063L, 2064L, 2065L, 2066L,
2067L, 2068L, 2069L, 2070L, 2071L, 2072L, 2073L, 2074L, 2075L,
2076L, 2077L, 2078L, 2079L, 2080L, 2081L, 2082L, 2083L, 2084L,
2085L, 2086L, 2087L, 2088L, 2089L, 2090L, 2091L, 2092L, 2093L,
2094L, 2095L, 2096L, 2097L, 2098L, 2099L, 2100L, 2101L, 2102L,
2103L, 2104L, 2105L))
我可以使用以下代码绘制三条线:
plot(f$age,f$weight)
curve(qdata$intercept1 + qdata$slope1*x, add=T, from=0, to=qdata$breakpoint1, col=2)
curve(qdata$intercept2 + qdata$slope2*x, add=T, from=qdata$breakpoint1, to=qdata$breakpoint2, col=2)
curve(qdata$intercept3 + qdata$slope3*x, add=T, from=qdata$breakpoint2, to=max(f$age), col=2)
出于我的目的,第三段的斜率没有生物学意义,因此为了呈现数据,我想将第三段的斜率设置为零:
plot(f$age,f$weight)
curve(qdata$intercept1 + qdata$slope1*x, add=T, from=0, to=qdata$breakpoint1, col=2)
curve(qdata$intercept2 + qdata$slope2*x, add=T, from=qdata$breakpoint1, to=qdata$breakpoint2, col=2)
curve(qdata$intercept3 + 0*x, add=T, from=qdata$intecept3, to=max(f$age), col=2)
但是,当我这样做时,我在第二条线段的末尾和第三条线段的开头之间出现了间隙。我想知道是否有人知道如何在将第三条线的斜率设置为零的同时保持第二条和第三条线的连接。
您提供的代码有两个问题。要使趋势线在 x-axis 上的正确位置开始,您只需修复我认为是代码中的拼写错误:
curve(qdata$intercept3 + 0*x, add=T, from=qdata$intecept3, to=max(f$age), col=2)
应该写成:
curve(qdata$intercept3 + 0*x, add=T, from=qdata$breakpoint2, to=max(f$age), col=2)
y-axis 上不连续的原因稍微复杂一些,但仍然很容易修复。原始线与第二条线的末端完美连接,因为它从 y-intercept 开始并略微向下趋势。当您将斜率重置为 0 时,新线将投射到所需点上方。因此,要绘制所需的线,您需要 re-calculate y 截距,这将产生一条穿过第二条趋势线末端的平线:
qdata$fake.intercept <- qdata$intercept2 + qdata$slope2 * qdata$breakpoint2
curve(qdata$fake.intercept + 0 * x, add = T, from = qdata$breakpoint2, to = max(f$age), col = 2)
这应该会产生下图,我相信这就是您想要的: