使用 drm 函数在一个图上绘制多条拟合曲线
Plot several fitted curves on one plot with drm function
我正在尝试绘制一些数据,这些数据已经安装了 R 中 drc 包中的 drm()
函数。我希望在同一图中有几条曲线相互重叠。
我可以像这样得到一条拟合曲线,其余未拟合成一条曲线:
#This is only mock data to show the concept
library(drc)
CurveData1 <- c(1, 1.1, 1.2, 1.3,2,3,4,5,5.2,5.4, 5.5, 5.6)
CurveData2 <- c(2, 2.1, 2.2, 2.3,3,4,5,6,6.2,6.4, 6.5, 6.6)
CurveData3 <- c(3, 3.1, 3.2, 3.3,4,5,6,7,7.2,7.4, 7.5, 7.6)
Conc <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
fit1 <- drm(CurveData1 ~ Conc, fct = LL.5())
plot(fit1, col = "black")
lines(CurveData2, Conc, col = "orange", type = "b")
lines(CurveData3, Conc, col = "blue", type = "b")
但是,当我尝试将所有拟合曲线放入同一个图中时,如下所示:
#This is only mock data to show the concept
library(drc)
CurveData1 <- c(1, 1.1, 1.2, 1.3,2,3,4,5,5.2,5.4, 5.5, 5.6)
CurveData2 <- c(2, 2.1, 2.2, 2.3,3,4,5,6,6.2,6.4, 6.5, 6.6)
CurveData3 <- c(3, 3.1, 3.2, 3.3,4,5,6,7,7.2,7.4, 7.5, 7.6)
Conc <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
fit1 <- drm(CurveData1 ~ Conc, fct = LL.5())
fit2 <- drm(CurveData2 ~ Conc, fct = LL.5())
fit3 <- drm(CurveData3 ~ Conc, fct = LL.5())
plot(fit1, col = "black")
lines(fit2, col = "orange", type = "b")
lines(fit3, col = "blue", type = "b")
我收到以下错误消息:
Error in xy.coords(x, y) :
'x' is a list, but does not have components 'x' and 'y'
知道为什么会发生这种情况以及如何解决它吗?是lines()
函数的限制还是plot()
函数的限制?
这样做有用吗?
library(drc)
library(ggplot2)
CurveData1 <- as.data.frame(as.matrix(c(1, 1.1, 1.2, 1.3,2,3,4,5,5.2,5.4, 5.5, 5.6)))
CurveData2 <- as.data.frame(as.matrix(c(2, 2.1, 2.2, 2.3,3,4,5,6,6.2,6.4, 6.5, 6.6)))
CurveData3 <- as.data.frame(as.matrix(c(3, 3.1, 3.2, 3.3,4,5,6,7,7.2,7.4, 7.5, 7.6)))
CurveData1$type = '1'
CurveData2$type = '2'
CurveData3$type = '3'
Conc <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
all = rbind(CurveData1,CurveData2,CurveData3)
all$conc = rep(Conc,3)
ggplot(all, aes(x = conc, y = V1, col = type))+
geom_point()+
geom_smooth(method = drm, method.args = list(fct = LL.5()), se = FALSE)
结果:
如果我只使用 plot
和 add = TRUE
,我不会 运行 出错。此外,如果您查看 ?plot.drc
,您会发现如何将 plot()
函数与 drc
对象一起使用。
library(drc)
CurveData1 <- c(1, 1.1, 1.2, 1.3,2,3,4,5,5.2,5.4, 5.5, 5.6)
CurveData2 <- c(2, 2.1, 2.2, 2.3,3,4,5,6,6.2,6.4, 6.5, 6.6)
CurveData3 <- c(3, 3.1, 3.2, 3.3,4,5,6,7,7.2,7.4, 7.5, 7.6)
Conc <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
fit1 <- drm(CurveData1 ~ Conc, fct = LL.5())
fit2 <- drm(CurveData2 ~ Conc, fct = LL.5())
fit3 <- drm(CurveData3 ~ Conc, fct = LL.5())
plot(fit1)
plot(fit2, add = TRUE, col = "orange")
plot(fit3, add = TRUE, col = "blue")
由 reprex package (v2.0.0)
于 2021-08-09 创建
我正在尝试绘制一些数据,这些数据已经安装了 R 中 drc 包中的 drm()
函数。我希望在同一图中有几条曲线相互重叠。
我可以像这样得到一条拟合曲线,其余未拟合成一条曲线:
#This is only mock data to show the concept
library(drc)
CurveData1 <- c(1, 1.1, 1.2, 1.3,2,3,4,5,5.2,5.4, 5.5, 5.6)
CurveData2 <- c(2, 2.1, 2.2, 2.3,3,4,5,6,6.2,6.4, 6.5, 6.6)
CurveData3 <- c(3, 3.1, 3.2, 3.3,4,5,6,7,7.2,7.4, 7.5, 7.6)
Conc <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
fit1 <- drm(CurveData1 ~ Conc, fct = LL.5())
plot(fit1, col = "black")
lines(CurveData2, Conc, col = "orange", type = "b")
lines(CurveData3, Conc, col = "blue", type = "b")
但是,当我尝试将所有拟合曲线放入同一个图中时,如下所示:
#This is only mock data to show the concept
library(drc)
CurveData1 <- c(1, 1.1, 1.2, 1.3,2,3,4,5,5.2,5.4, 5.5, 5.6)
CurveData2 <- c(2, 2.1, 2.2, 2.3,3,4,5,6,6.2,6.4, 6.5, 6.6)
CurveData3 <- c(3, 3.1, 3.2, 3.3,4,5,6,7,7.2,7.4, 7.5, 7.6)
Conc <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
fit1 <- drm(CurveData1 ~ Conc, fct = LL.5())
fit2 <- drm(CurveData2 ~ Conc, fct = LL.5())
fit3 <- drm(CurveData3 ~ Conc, fct = LL.5())
plot(fit1, col = "black")
lines(fit2, col = "orange", type = "b")
lines(fit3, col = "blue", type = "b")
我收到以下错误消息:
Error in xy.coords(x, y) : 'x' is a list, but does not have components 'x' and 'y'
知道为什么会发生这种情况以及如何解决它吗?是lines()
函数的限制还是plot()
函数的限制?
这样做有用吗?
library(drc)
library(ggplot2)
CurveData1 <- as.data.frame(as.matrix(c(1, 1.1, 1.2, 1.3,2,3,4,5,5.2,5.4, 5.5, 5.6)))
CurveData2 <- as.data.frame(as.matrix(c(2, 2.1, 2.2, 2.3,3,4,5,6,6.2,6.4, 6.5, 6.6)))
CurveData3 <- as.data.frame(as.matrix(c(3, 3.1, 3.2, 3.3,4,5,6,7,7.2,7.4, 7.5, 7.6)))
CurveData1$type = '1'
CurveData2$type = '2'
CurveData3$type = '3'
Conc <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
all = rbind(CurveData1,CurveData2,CurveData3)
all$conc = rep(Conc,3)
ggplot(all, aes(x = conc, y = V1, col = type))+
geom_point()+
geom_smooth(method = drm, method.args = list(fct = LL.5()), se = FALSE)
结果:
如果我只使用 plot
和 add = TRUE
,我不会 运行 出错。此外,如果您查看 ?plot.drc
,您会发现如何将 plot()
函数与 drc
对象一起使用。
library(drc)
CurveData1 <- c(1, 1.1, 1.2, 1.3,2,3,4,5,5.2,5.4, 5.5, 5.6)
CurveData2 <- c(2, 2.1, 2.2, 2.3,3,4,5,6,6.2,6.4, 6.5, 6.6)
CurveData3 <- c(3, 3.1, 3.2, 3.3,4,5,6,7,7.2,7.4, 7.5, 7.6)
Conc <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
fit1 <- drm(CurveData1 ~ Conc, fct = LL.5())
fit2 <- drm(CurveData2 ~ Conc, fct = LL.5())
fit3 <- drm(CurveData3 ~ Conc, fct = LL.5())
plot(fit1)
plot(fit2, add = TRUE, col = "orange")
plot(fit3, add = TRUE, col = "blue")
由 reprex package (v2.0.0)
于 2021-08-09 创建