【发布时间】:2018-05-08 22:48:31
【问题描述】:
我正在尝试添加一条具有自定义截距和斜率的线。我知道我可以使用geom_abline,但这条线超出了绘图的边缘。
我有以下数据。
>table
intent observed true
0 0.00 0.07
.1-.3 0.19 0.19
.4-.6 0.51 0.41
.7-.9 0.79 0.48
1 1.00 0.53
这里是dput()
structure(list(intent = structure(c(4L, 1L, 2L, 3L, 5L), .Label = c(".1-.3",
".4-.6", ".7-.9", "0", "1"), class = "factor"), observed = c(0,
0.19, 0.51, 0.79, 1), true = c(0.07, 0.19, 0.41, 0.48, 0.53)), row.names = c(NA,
-5L), class = "data.frame", .Names = c("intent", "observed",
"true"))
这是我目前的解决方案
table %>%
ggplot(aes(y=true,x=observed))+
geom_point()+
geom_smooth(method = lm,se=F,color="black",lty=2,size=1/2)+
geom_abline(intercept=0.07, slope=0.599,size=1/2)
问题在于geom_abline 是一种参考线。因此,它超过了 0 附近的绘图边缘,并且在 x 轴上超过 0.8 时不完全可见,这与 geom_smooth 在绘图区域中保留一条线相反。我怎样才能让我的geom_abline 在geom_smooth 中工作,使其适合绘图区域。
【问题讨论】:
-
你能
dput()你的数据吗?