【发布时间】:2016-05-16 12:47:52
【问题描述】:
使用 ggplot,我显示了一系列点、一个三阶多项式拟合(带有相应的公式和 R2 值)和一个用于比较的标准化函数。
ggplot(aes(x = saturation, y = time_norm_ratio), data = tmp) + geom_point(aes(color = id)) +
geom_line(aes(x=saturation,y=BPR_time_norm_ratio,color="BPR function")) + geom_smooth(aes(color = id), method= "lm", se = F, formula=y ~ poly(x, 3, raw=TRUE)) +
ggtitle("Saturation time delay curve") +
labs(x="Saturation",y="Time (t/to)") +
stat_poly_eq(aes(label=paste(..eq.label..,..adj.rr.label.., sep = "~~~")),geom="label",alpha=0.33,formula=(y ~ poly(x, 3, raw=TRUE)),label.y=2.5,parse=TRUE) +
theme(text=element_text(size=20))
给我:
但是,当我正在绘制一系列文件时,我希望标准化绘图上 stat_poly_eq 框的位置。目前固定为 y=2.5 (label.y=2.5)。是否可以相对于 y 轴动态设置它的 y 位置?
我尝试了以下方法:
label.y=(0.75(tmp.time_norm_ratio)
但这导致:
ggplot2::layer 中的错误(stat = StatPolyEq,数据 = 数据,映射 = 映射,: 尝试应用非函数
【问题讨论】:
-
认为问题可能出在
0.75(tmp.time_norm_ratio),应该是0.75 * tmp$time_norm_ratio吗?可能还需要一些聚合,比如label.y = 0.75 * max(tmp$time_norm_ratio)。 -
正确!随意发布作为答案