Dose-response curve, geom_point

52 Views Asked by At

I plotted the dose-response curve with the code below. However, the points on the graph don't seem to be correct. I would like to know how to plot the y-values corresponding to the x-values with the correct points.

library(drc)
library(tidyverse)

response_irgarol <- as.numeric(c("6.666667", "10", "10", "46.66667", "46.66667", "56.66667", "96.66667", "100"))
irgarol <- as.numeric(c("0", "2", "10", "20", "100", "200", "1000", "2000"))
df <- data.frame(irgarol, response_irgarol)
I <- drm(response_irgarol ~ irgarol, data = df, fct = LL.4())
newdata <- expand.grid(irgarol=exp(seq(log(0.5), log(2000), length=10000)))

pm <- predict(I, newdata = newdata, interval = "confidence")

newdata$p <- pm[,1]
newdata$pmin <- pm[,2]
newdata$pmax <- pm[,3]

df$irgarol0 <- df$irgarol
df$irgarol0[df$irgarol0 == 0] <- 0.5

ed50 <- ED(I, 50, type = "absolute", interval = "delta")
coefs <- setNames(ed50[1], "e")
y50 <- predict(I, newdata = data.frame(irgarol = ed50))

ggplot(df, aes(x=irgarol0, y=response_irgarol))+
  geom_point(shape=21, size=3, stroke=1, colour='#0081C9')+
  geom_line(data = newdata, aes(x = irgarol, y = p), lwd=1, color='#0081C9')+
  coord_trans(x="log")+
  geom_segment(aes(x=coefs["e"], y=0, xend= coefs["e"], yend=y50), lty=2, lwd=0.8, colour="gray50")+
  geom_segment(aes(x=coefs["e"], y=y50, xend=0, yend=y50), lty=2, lwd=0.8, colour="gray50")+
  scale_x_log10(limits = c(2, 10000), breaks = c(2, 10, 20, 50, round(coefs["e"]), 200, 1000, 5000), labels = c(2, 10, 20, 100, round(coefs["e"]), 200, 1000, 2000))+
  xlab("Irgarol 1051 (ug/L)")+ylab("Mortality (%)")+
  theme(axis.text.x = element_text(angle = 90))+
  theme_classic()
0

There are 0 best solutions below