【发布时间】:2019-11-14 18:39:08
【问题描述】:
我正在尝试通过geom_segment 在绘图中添加参考线。
一个简化的例子:
tryCatch({
spaghetti_smooth_ref = qplot(age,T_self, data=sest,geom="blank") +
geom_smooth(method='lm',alpha=0.1, colour = "black") +
geom_segment(aes(x = 16, xend = 45,y = coef(us_ref)["(Intercept)"], yend = coef(us_ref)["(Intercept)"] + coef(us_ref)["age"] * 45), linetype = "solid", colour = "#5e8fb0", alpha = 0.5, size = 0.1) +
facet_wrap(~ country)+
scale_linetype_discrete()
}, error = function(e){warning(e)})
如下所示,geom_smooth() 的渲染比geom_segment() 平滑得多。
我该如何改进?在 Mac 上的 Rstudio 中查看和呈现为 PDF 时是相同的。我还使用原始数据和geom_smooth() 绘制了完全相同的斜率,使用geom_segment() 绘制了一次,它们仍然不同。
【问题讨论】:
-
annotate('segment')有效。 See posting here.