0

我正在尝试绘制一些已符合drm()R 中 drc 包中的函数的数据。我希望在同一个图中有几条曲线相互重叠。

我可以得到一条拟合曲线,其余的不拟合成这样的曲线:

#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")

我收到以下错误消息:

xy.coords(x, y) 中的错误:“x”是一个列表,但没有组件“x”和“y”

知道为什么会发生这种情况以及如何解决它吗?是lines()功能限制还是plot()功能限制?

4

2 回答 2

1

这是在耍花招吗?

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)

结果:

在此处输入图像描述

于 2021-08-09T10:06:07.193 回答
1

plot如果我只使用and ,我不会遇到错误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 包于 2021-08-09 创建 (v2.0.0 )

于 2021-08-09T10:07:52.653 回答