现在,我有了一个数据集,该数据集的x轴上有temperature
(自变量),沿y轴的蒸腾过程中从树木的木质部测得的sapflow
的比率。
我根据下面的数据(散点图1)创建了一个scatterplot
。我想使用函数abline()
或也许做同样工作的另一个函数来绘制最佳拟合线。但是,我的r代码(如下)似乎在我的绘图的左下角绘制了最合适的线,这似乎不正确。
Rcode
plot(Sapflow$Sapflow, Sapflow$Temperature,
main="Scatterplot of Temperature (°C)",
xlab="Temperature (°C)",
ylab=expression(paste("Sapflow Litres day"^{-1})),
pch=19,
col="red")
##Line of best fit
abline(lm(Sapflow$Sapflow~Sapflow$Temperature), col="blue")
目标
我的散点图总体上呈负相关,我可以想象到最合适的线实际上会稍微弯曲。即使我不能在没有最佳配合线的真实视觉表示的情况下也不能确定地说,我可以设想它的外观与散点图2相似。有人可以伸出援手吗?
散点图1
散点图2
参考:“ Quick R”
https://www.statmethods.net/graphs/images/scatterplot2.jpg
数据
structure(list(Date = structure(c(31L, 42L, 53L, 55L, 56L, 57L,
58L, 59L, 60L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 54L, 61L, 72L,
83L, 86L, 87L, 88L, 89L, 90L, 91L, 62L, 63L, 64L, 65L, 66L, 67L,
68L, 69L, 70L, 71L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L,
82L, 84L, 85L, 92L, 103L, 114L, 117L, 118L, 119L, 120L, 121L,
122L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 104L,
105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 115L, 116L,
123L, 134L, 145L, 147L, 148L, 149L, 150L, 151L, 152L, 124L, 125L,
126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 135L, 136L, 137L,
138L, 139L, 140L, 141L, 142L, 143L, 144L, 146L, 1L, 12L, 23L,
25L, 26L, 27L, 28L, 29L, 30L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L
), .Label = c("10/1/18", "10/10/18", "10/11/18", "10/12/18",
"10/13/18", "10/14/18", "10/15/18", "10/16/18", "10/17/18", "10/18/18",
"10/19/18", "10/2/18", "10/20/18", "10/21/18", "10/22/18", "10/23/18",
"10/24/18", "10/25/18", "10/26/18", "10/27/18", "10/28/18", "10/29/18",
"10/3/18", "10/30/18", "10/4/18", "10/5/18", "10/6/18", "10/7/18",
"10/8/18", "10/9/18", "6/1/18", "6/10/18", "6/11/18", "6/12/18",
"6/13/18", "6/14/18", "6/15/18", "6/16/18", "6/17/18", "6/18/18",
"6/19/18", "6/2/18", "6/20/18", "6/21/18", "6/22/18", "6/23/18",
"6/24/18", "6/25/18", "6/26/18", "6/27/18", "6/28/18", "6/29/18",
"6/3/18", "6/30/18", "6/4/18", "6/5/18", "6/6/18", "6/7/18",
"6/8/18", "6/9/18", "7/1/18", "7/10/18", "7/11/18", "7/12/18",
"7/13/18", "7/14/18", "7/15/18", "7/16/18", "7/17/18", "7/18/18",
"7/19/18", "7/2/18", "7/20/18", "7/21/18", "7/22/18", "7/23/18",
"7/24/18", "7/25/18", "7/26/18", "7/27/18", "7/28/18", "7/29/18",
"7/3/18", "7/30/18", "7/31/18", "7/4/18", "7/5/18", "7/6/18",
"7/7/18", "7/8/18", "7/9/18", "8/1/18", "8/10/18", "8/11/18",
"8/12/18", "8/13/18", "8/14/18", "8/15/18", "8/16/18", "8/17/18",
"8/18/18", "8/19/18", "8/2/18", "8/20/18", "8/21/18", "8/22/18",
"8/23/18", "8/24/18", "8/25/18", "8/26/18", "8/27/18", "8/28/18",
"8/29/18", "8/3/18", "8/30/18", "8/31/18", "8/4/18", "8/5/18",
"8/6/18", "8/7/18", "8/8/18", "8/9/18", "9/1/18", "9/10/18",
"9/11/18", "9/12/18", "9/13/18", "9/14/18", "9/15/18", "9/16/18",
"9/17/18", "9/18/18", "9/19/18", "9/2/18", "9/20/18", "9/21/18",
"9/22/18", "9/23/18", "9/24/18", "9/25/18", "9/26/18", "9/27/18",
"9/28/18", "9/29/18", "9/3/18", "9/30/18", "9/4/18", "9/5/18",
"9/6/18", "9/7/18", "9/8/18", "9/9/18"), class = "factor"),
Temperature = c(85.07,
79.72, 72.83, 90.1, 83.02, 73.34, 77.11, 74.79, 81.66, 77.71,
66.14, 78.15, 69.33, 68.13, 60.31, 69.47, 81.86, 78.63, 77.69,
77.56, 52.88, 53.32, 53.74, 55.85, 49.56, 55.3, 69.25, 74.96,
69.29, 60.07, 54.31, 48.6, 55.73, 56.74, 47.66, 60.51, 55.64,
58.39, 63.8, 63.16, 73.65, 71.08, 64.34, 60.1, 51.61, 54.87,
58.23, 52.49, 52.56, 59.64, 67.85, 64.42, 60.08, 59.71, 57.12,
58.7, 68.85, 72.44, 89.13, 77.67, 62.17, 61.3, 63.58, 66.26,
60.09, 56.63, 53.11, 59.84, 60.06, 80.76, 79.51, 73.96, 84.58,
78.77, 71.65, 72.59, 77.52, 69.04, 78.26, 77.22, 73.75, 81.95,
82.04, 78.14, 73.41, 72.76, 90.68, 74.24, 71.3, 74.4, 60.26,
66.08, 65.18, 57.17, 66.88, 75.53, 71.52, 74.97, 66.02, 78.06,
73.58, 68.18, 83.55, 80.4, 66.28, 72.32, 72.39, 77.74, 69.81,
74.21, 77.37, 88.28, 65.33, 87.54, 80.49, 69.58, 68.18, 69.25,
60.06, 66.38, 68.51, 71.65, 63.29, 76.63, 80.46, 85.56, 81.25,
94.48, 73.87, 76.8, 72.83, 77.55, 81.5, 77.7, 75.79, 94.38, 99.55,
94.14, 87.29, 84.81, 82.63, 85.27, 84.52, 71.13, 76.28, 78.06,
82.83, 75.18, 83.8, 85.38, 84, 85.33),
Humidity = c(19.67, 18.82,
20.38, 14.94, 12.92, 15.28, 15.12, 16.05, 15.19, 16.67, 18.69,
14.61, 16.71, 17.35, 16.98, 15.44, 15.21, 18.62, 20.11, 18.64,
15.66, 17.2, 18.21, 19.32, 23.02, 21.69, 18.03, 18.46, 18.45,
20.78, 23.04, 22.05, 19.71, 20.59, 24.89, 23.34, 24.7, 24.2,
22.43, 18.21, 17.66, 18.23, 20.36, 22.83, 23.52, 22.88, 19.59,
21.51, 22.25, 21.47, 22.03, 22.51, 25.54, 24.01, 24.28, 26.21,
23.72, 17.63, 17.27, 19.19, 19.97, 19.84, 22.78, 24.46, 23.05,
23.31, 24.75, 23.23, 18.91, 15.56, 13.51, 15.8, 17.67, 19.18,
18.93, 20.05, 17.1, 16.87, 18.77, 20.49, 21.5, 18.04, 18.82,
17.38, 13.05, 13.13, 13.48, 16.32, 16.74, 16.11, 15.77, 15.48,
18.17, 18.16, 18.44, 16.63, 16.64, 14.47, 13.07, 14.14, 17.27,
16.71, 18.22, 12.9, 13.95, 14.7, 15.78, 17.52, 19.66, 18.87,
18.07, 16.4, 12.92, 10.57, 10.04, 9.78, 10.24, 14.25, 15.92,
11.59, 9.25, 10.33, 11.22, 15.03, 13.67, 14.26, 15.42, 8.34,
8.56, 12.37, 14.38, 15.47, 16.4, 17.15, 20.05, 11.08, 10.63,
14.34, 13.27, 9.33, 8.1, 10.95, 12.79, 8.64, 11.42, 12.12, 9.91,
7.86, 3.51, 4.97, 3.63, 5.59),
Radiation = c(197.8, 195.5, 288,
72, 160.5, 337.1, 176.9, 242.3, 189.4, 295.7, 363.2, 158, 290,
251.2, 297.3, 192.6, 163.5, 274.5, 210.7, 243.4, 287.4, 375.7,
290.5, 336.4, 361.6, 369.2, 302.6, 295.2, 348.5, 343.5, 327.6,
358.9, 358.6, 288.9, 325.6, 307.8, 321.3, 321.5, 280.6, 264.9,
253, 279.5, 318.1, 285.1, 330.8, 252, 201, 229.9, 259.3, 230.4,
265.5, 214.1, 307, 311.1, 282.5, 256.9, 227.2, 263.4, 68.2, 130.8,
276.6, 299.2, 276.5, 243.9, 291, 289.3, 290.6, 259.6, 220.5,
72.7, 158.9, 233.8, 105.9, 164.2, 168.1, 188.7, 120.1, 217.7,
111.2, 114.7, 143.6, 55.2, 108.5, 162.2, 185, 197.7, 54.1, 126.3,
111.2, 135.4, 228.3, 214.3, 240.1, 247.6, 173, 172.4, 131.9,
149.4, 203.1, 92.3, 168.5, 146.6, 65.9, 103.6, 200.2, 131.3,
183.5, 128.3, 140.6, 124.1, 125.9, 75.8, 173.2, 47.9, 111.7,
205.8, 188.3, 175.6, 193.7, 170.4, 188.3, 108, 171.1, 59.5, 87.7,
142.2, 111.8, 26.3, 129.9, 103.1, 158.7, 147.9, 109.8, 67.8,
106.6, 12.3, 15.8, 53, 63.4, 86.2, 123.3, 112.9, 128.2, 141.9,
81.6, 102, 86.8, 83.9, 50, 96.8, 100.5, 47),
Sapflow = c(14.97,
16.31, 17.52, 7.45, 12.18, 15.82, 11.79, 14.45, 10.95, 13.62,
16.28, 11.42, 16.13, 15.09, 17.28, 14.43, 11.7, 16.06, 17.66,
16.33, 17.79, 18.58, 19.41, 19.8, 21.63, 21.35, 17.81, 17.56,
19.37, 21.27, 23.26, 23.67, 22.64, 21.85, 24.81, 22.36, 24.72,
23.87, 23.67, 22.01, 19.23, 19.92, 21.99, 23.6, 24.9, 24.46,
22.22, 23.95, 24.81, 23.88, 22.98, 24.47, 26.09, 25.97, 25.82,
26.24, 25.09, 22, 16.91, 21.35, 25.32, 25.76, 26.38, 25.78, 25.77,
25.15, 26.29, 26.22, 24.59, 18.26, 18.91, 21.57, 21.37, 21.29,
23.96, 24.85, 21.02, 23.05, 22.69, 23.9, 25.24, 25.4, 23.19,
22.8, 22.08, 21.86, 13.82, 22.05, 23.21, 20.12, 22.73, 21.88,
23.33, 24.76, 23.5, 22.06, 22.01, 20.65, 21.54, 19.9, 21.67,
21.84, 18.82, 17.99, 21.41, 23.53, 23.39, 25.75, 22.62, 22.25,
21.81, 16.81, 20.42, 12.08, 12.36, 15.31, 14.14, 15.48, 15.18,
14.19, 12.09, 12.39, 12.34, 12.61, 10.79, 10.53, 11.29, 9.92,
9.79, 10.86, 10.98, 10.58, 12.54, 12.52, 12.25, 6.38, 0.91, 5.24,
6.56, 5.72, 4.55, 4.99, 2.88, 0.99, 1.03, 1.57, 2.07, 2.3, 2.22,
2.11, 2.21, 2.29)),
class = "data.frame", row.names = c(NA, -152L))
答案 0 :(得分:2)
您的原始(线性)拟合似乎不正确,因为您在对plot
的调用中未正确指定列。默认情况下,第一个参数用于x轴,而不用于y轴,但是您可以通过明确分配y = Sapflow$Sapflow
和x = Sapflow$Temperature
来更改此参数。因此,使用abline
拟合 linear 拟合数据(以树汁流量作为因变量,以温度作为预测变量)的样子如下:
plot(y = Sapflow$Sapflow, x = Sapflow$Temperature,
main="Scatterplot of Temperature (°C)",
xlab="Temperature (°C)",
ylab=expression(paste("Sapflow Litres day"^{-1})),
pch=19,
col="red")
abline(lm(Sapflow$Sapflow ~ Sapflow$Temperature))
如果要拟合数据平滑曲线,可以使用scatter.smooth
:
scatter.smooth(y = Sapflow$Sapflow, x = Sapflow$Temperature,
main="Scatterplot of Temperature (°C)",
xlab="Temperature (°C)",
ylab=expression(paste("Sapflow Litres day"^{-1})),
pch=19,
col="red")