【发布时间】:2020-12-08 11:38:26
【问题描述】:
我使用以下代码创建了时间(x 轴)和 HDL 胆固醇(y 轴)之间关系的散点图。数据按性别着色,我想仅通过 x 轴上的特定值范围拟合回归线。我的时间数据范围从 20 到 180 天,但我只想拟合一条 30-90 天的回归线,同时仍显示绘图上的所有数据。我应该如何修改代码来实现这一点?
add = "reg.line",
conf.int = TRUE,
color = "Sex", alpha=0.5)+
stat_cor(aes(color= Sex),method = "spearman")+
scale_color_manual(values = c("#9c0d4b", "#7ca0d4"))+
scale_x_continuous(breaks = seq(0, 80, by = 10))+
scale_y_continuous(breaks=seq(0, 10,2), limits=c(0,10))+
geom_hline(yintercept=1.37, linetype="dotted", color = "black")+
xlab("Time (days)") + ylab("HDL")+
theme(legend.position = "none")+
theme(text = element_text(size = 11))```
Thanks in advance!
【问题讨论】:
标签: r ggplot2 linear-regression scatter-plot lm