[英]How to draw logistic growth curve on my ggplot
I've got some data that looks like a logistic growth curve.我有一些看起来像逻辑增长曲线的数据。 I can put a loess curve on it with geom_smooth, but I'd like to fit a proper logistic curve我可以用 geom_smooth 在上面放一条黄土曲线,但我想拟合一条合适的逻辑曲线
data <- data.frame(conc = c(10, 1, 0.1, 0.01, 0.001, 1e-04, 1e-05, 1e-06, 1e-07, 1e-08,
1e-09, 10, 1, 0.1, 0.01, 0.001, 1e-04, 1e-05, 1e-06, 1e-07, 1e-08,
1e-09, 10, 1, 0.1, 0.01, 0.001, 1e-04, 1e-05, 1e-06, 1e-08, 1e-09,
10, 1, 0.1, 0.01, 0.001, 1e-04, 1e-05, 1e-06, 1e-08, 1e-09, 1e-10),
value = c(22832, 26910, 9303, 4128, 521, 44, 64, 31, 50, 39, 284, 19993,
24205, 9230, 4030, 447, 42, 51, 175, 38, 35, 161, 23072, 27382,
7036, 2416, 320, 58, 30, 37, 40, 110, 26630, 28568, 6262, 2854,
314, 102, 50, 39, 34, 77, 30))
ggplot(data, aes(x=conc, y=value)) +
geom_point() +
geom_smooth() +
scale_x_continuous(trans = 'log10')
I've read around and tried with this:我已经阅读并尝试了这个:
stat_smooth(method="glm", method.args=list(family="binomial"), se=FALSE)``` stat_smooth(method="glm", method.args=list(family="binomial"), se=FALSE)```
But I keep getting this error:但我不断收到此错误:
geom_smooth()` using formula 'y ~ x'
Warning message:
Computation failed in `stat_smooth()`:
y values must be 0 <= y <= 1
I'm aiming for something like this:我的目标是这样的:
Something like this???像这样的???
ggplot(data, aes(x=conc, y=value/max(value))) +
geom_point() +
# geom_smooth() +
# scale_x_continuous(trans = 'log10')
stat_smooth(formula = "y ~ x", method = "glm",
method.args = list(family="quasibinomial"), se = T) +
scale_y_continuous(labels = function(x) x * max(data$value))
To fit a four-parameters logistic curve, you can do:要拟合四参数逻辑曲线,您可以执行以下操作:
library(ggplot2)
library(nlme)
ggplot(data, aes(x=conc, y=value)) +
geom_point() +
geom_smooth(
method = "nls", formula = y ~ SSfpl(log(x), A, B, xmid, scal),
se = FALSE
)
But there's a singular gradient with your data, hence an error is generated.但是您的数据存在奇异梯度,因此会产生错误。 This works if one fits the logarithm of value
:如果符合value
的对数,则此方法有效:
ggplot(data, aes(x=conc, y=log(value))) +
geom_point() +
geom_smooth(
method = "nls", formula = y ~ SSfpl(log(x), A, B, xmid, scal),
se = FALSE
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.