So I have a dataframe like this:
a_data <-
data.frame(
f = f,
alpha = alpha,
asymptote = alpha_1_est)
并且需要一个这样的函数:
a_formula <- function(x) {
0.7208959 - 0.8049132 * exp(-21.0274 * x)}
我在使用ggplot2时使用它们:
ggplot(a_data, aes(x = f, y = alpha)) +
geom_point() +
#function curve
stat_function(fun = a_formula,
color = "red") +
#asymptote of alpha
geom_hline(
yintercept = asymptote,
linetype = "longdash",
color = "blue")
这将产生如下图所示的绘图:
![basic plot](https://istack.dev59.com/cvEj9.webp)
y
轴、函数曲线(红色)和渐近线(虚线)之间填充区域,就像这样:
![shaded plot](https://istack.dev59.com/ArE1R.webp)
这是数据框的外观:
> head(a_data)
f alpha asymptote
1 0.01 0.007246302 0.7208959
2 0.03 0.374720198 0.7208959
3 0.05 0.484362949 0.7208959
4 0.07 0.540090209 0.7208959
5 0.09 0.625383303 0.7208959
6 0.11 0.590898201 0.7208959
附言:我在Stack Overflow上比较新,所以如果我违反了任何规定或者弄乱了问题,请不要犹豫地指出来。
dput(a_data)
并粘贴输出吗?它应该足够小,可以完全复制。顺便说一句:你在构建问题和设置示例方面做得非常好。不过,在你的a_data
输出中没有f
,并且geom_hline()
调用将无法找到asymptote
,除非你是想在aes()
中使用它。 - hrbrmstrdput(a_data)
的输出非常大,所以我不确定将其添加到问题中是否是一个好主意(不能只将其粘贴到评论中,因为它太大了)。但我理解你的观点-下次我会更加仔细地考虑如何重现。谢谢你的时间! - somevasya