使用ggplot2为曲线拟合曲线?

时间:2018-03-29 10:21:36

标签: r dataframe ggplot2 data-fitting

给定数据帧df:

hour <- c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23)

fraction <- c(0.041034790, 0.063627419, 0.098259980, 0.129083665, 0.124113475, 
              0.086460033, 0.027706516, 0.010332713, 0.006020325, 0.005744794,
              0.006674574, 0.006529392, 0.007197982, 0.008230617, 0.011662787, 
              0.012966288, 0.012047173, 0.012051243, 0.011828668, 0.013063874,
              0.015974441, 0.017099757, 0.027717391, 0.029555940)

df <- data.frame(hour, fraction)

我正在尝试使用ggplot将曲线拟合到小时和分数。 它看起来像是偏向正态分布。

我如何拟合最佳线+公式。这就是我的尝试:

ggplot(df, aes(x = hour, y = fraction)) +
  geom_point() +
  scale_x_continuous(breaks = round(seq(min(df$hour, na.rm = TRUE), 
                                        max(df$hour, na.rm = TRUE), 
                                        by = 1),
                                    1)) + 
  stat_smooth(method = "lm", formula = y ~ poly(x, 5, raw = TRUE), color = 'red')

我应该扩展它以使它像正常分布一样吗? 或者我应该在这里使用Gamma发行版吗?

0 个答案:

没有答案