r - ggplot2中的中值回归线
问题描述
我正在尝试使用 ggplot 来拟合中值回归线。这使用了 quantreg 包的 rq() 函数。数据是来自 HSAUR3 包的云数据。这是我的代码:
seeding.no <- predict(rq(rainfall ~ sne, data = clouds, subset = seeding == "no"))
seeding.yes <- predict(rq(rainfall ~ sne, data = clouds, subset = seeding == "yes"))
clouds.predcit <- data.frame(Rainfall=clouds$rainfall, No=seeding.no, Yes=seeding.yes)
ggplot(clouds, aes(x=sne, y=rainfall, colour=clouds$seeding, shape=clouds$seeding)) +
geom_point(size=2) +
labs(title="Rainfall vs S-Ne Criterion", x="S-Ne Criterion", y="Rainfall") +
scale_color_manual(values=c("blue", "red")) +
scale_shape_manual(values=c(1,2)) +
geom_line(color="blue",data=clouds.predcit, aes(x=No, y=Rainfall)) +
geom_line(color="red",data=clouds.predcit, aes(x=Yes, y=Rainfall)) +
theme_minimal()
这就是我得到的:
这就是我想要得到的:
我的代码有什么问题?
解决方案
我用了:
geom_quantile(quantiles = 0.5)
并让它工作。毕竟不需要预测。
推荐阅读
- c++ - 在 C++ 中的 Z3 中获取位向量中的数值
- python - 反斜杠运算符在 Python 中的作用是什么?
- android - 循环显示动画在第一次通话中不起作用
- javascript - 'createConsumer' 不是由 node_modules/@rails/actioncable/app/assets/javascripts/action_cable.js 导出的
- c++ - C++ 输出对齐
- python - 如何获取非空值的百分比?
- c# - MongoDB .net 驱动程序 - 获取 MongoDB 服务器版本
- networking - 不用ip访问树莓派
- paypal - PayPal API 返回 RESOURCE_NOT_FOUND / INVALID_RESOURCE_ID 但交易列在 Sandbox Business 帐户中
- java - JsperReport 在 JavaFx 中不显示任何数据