ggplot2 散点图添加自定义置信区间带线;类似于 abline() 方法
ggplot2 scatter plot adding custom confidence interval bands lines; similar to abline() approach
问题背景:散点图;将 ggplot2 与来自数据框的数据一起使用;寻求添加自定义 geom-line() [或 geom_abline()] 以使用线性回归模型在离散数据上包含内部散点图置信区间上限和下限。
错误上下文:消息错误:提供给连续刻度的离散值
是的,我知道并理解数据是离散的。对于允许拟合自定义线位置的显示线,建议将线添加到数字数据中?与 cars::scatterplot() 对显示的四分位数线位置所做的类似,但我试图添加自定义置信区间上限和下限。对于推荐的 ggplot2:geom_line() 或 geom_segment() 或 geom_abline()?
ggplot(nt, aes(x=hr, y=temp)) + geom_point(aes(color=temp), size=3) +
scale_color_gradientn(colors = c("#00AFBB", "#E7B800", "#FC4E97")) +
geom_line(data=nt, aes(x = hr, y = temp, color = 'black'))
示例数据:数据帧'nt'(更正:nt、normtemp、同名)
temp
<dbl>
hr
<int>
1 96.3 70
2 96.7 71
3 96.9 74
4 97.0 80
5 97.1 73
6 97.1 75
使用 plot(),而不是 ggplot() + geom_point(),我确实完成了为上带和下带绘制的散点图置信区间。
这是通过使用
完成的
ylimits <- c(min(fitted.pred[,"lwr"]), max(fitted.pred[,"upr"]))
并将 ylim=ylimits 应用于绘图参数:
plot(df, ylim=ylimits)
并为置信区间的模型线添加 abline(model),并为不同的置信区间水平多次设置线,其中 xplot = data.frame:
lines(xplot[,], fitted.conf_int[,"lwr"])
问题背景:散点图;将 ggplot2 与来自数据框的数据一起使用;寻求添加自定义 geom-line() [或 geom_abline()] 以使用线性回归模型在离散数据上包含内部散点图置信区间上限和下限。
错误上下文:消息错误:提供给连续刻度的离散值
是的,我知道并理解数据是离散的。对于允许拟合自定义线位置的显示线,建议将线添加到数字数据中?与 cars::scatterplot() 对显示的四分位数线位置所做的类似,但我试图添加自定义置信区间上限和下限。对于推荐的 ggplot2:geom_line() 或 geom_segment() 或 geom_abline()?
ggplot(nt, aes(x=hr, y=temp)) + geom_point(aes(color=temp), size=3) +
scale_color_gradientn(colors = c("#00AFBB", "#E7B800", "#FC4E97")) +
geom_line(data=nt, aes(x = hr, y = temp, color = 'black'))
示例数据:数据帧'nt'(更正:nt、normtemp、同名)
temp
<dbl>
hr
<int>
1 96.3 70
2 96.7 71
3 96.9 74
4 97.0 80
5 97.1 73
6 97.1 75
使用 plot(),而不是 ggplot() + geom_point(),我确实完成了为上带和下带绘制的散点图置信区间。
这是通过使用
完成的ylimits <- c(min(fitted.pred[,"lwr"]), max(fitted.pred[,"upr"]))
并将 ylim=ylimits 应用于绘图参数:
plot(df, ylim=ylimits)
并为置信区间的模型线添加 abline(model),并为不同的置信区间水平多次设置线,其中 xplot = data.frame:
lines(xplot[,], fitted.conf_int[,"lwr"])