R语言 我如何平滑曲线在我的情节?

uyhoqukh  于 2023-04-27  发布在  其他
关注(0)|答案(1)|浏览(137)

我有这些图,我希望曲线更平滑。我如何将其添加到我的代码中?谢谢!

plot(PA_Spe_accum, ci = 1.96, ci.type = "bar", las=1, col = "green3", lty = 1, lwd=2, ci.col = "green3", ci.lty = 1, xlim=c(0,60), ylim=c(0,70))
plot(PA_Spe2_accum, add = TRUE, ci = 1.96, ci.type = 'bar', lwd=2, col = 'royalblue4', lty = 1, ci.col = 'royalblue4', ci.lty = 1)

我试着用lowess,但我不确定如何把它写进我的代码。

sdnqo3pr

sdnqo3pr1#

出现,PA_Spe_accumPA_Spe2_accum是列表而不是数字向量,这导致了错误。您可以尝试在使用黄土函数之前将它们转换为数字向量。以下是如何修改代码以实现所需的平滑。

PA_Spe_accum_vec <- unlist(PA_Spe_accum)
PA_Spe2_accum_vec <- unlist(PA_Spe2_accum)
smooth_PA_Spe_accum <- loess(PA_Spe_accum_vec ~ seq_along(PA_Spe_accum_vec))
smooth_PA_Spe2_accum <- loess(PA_Spe2_accum_vec ~ seq_along(PA_Spe2_accum_vec))

smoothed_PA_Spe_accum <- predict(smooth_PA_Spe_accum)
smoothed_PA_Spe2_accum <- predict(smooth_PA_Spe2_accum)
plot(smoothed_PA_Spe_accum, ci = 1.96, ci.type = "bar", las=1, col = "green3", lty = 1, lwd=2, ci.col = "green3", ci.lty = 1, xlim=c(0,60), ylim=c(0,70))
lines(smoothed_PA_Spe2_accum, lwd=2, col = 'royalblue4', add = TRUE)

请让我知道这是否有帮助。

相关问题