Dose-response curve, geom_segment

15 views Asked by At

When use the function of scale_x_continuous, geom_segment of y axis dose not working. (x=coefs["e"], y=y50, xend=0, yend=y50) Wheon use the function of scale_x_log10, it dose work but x axis labels are very weird. So I want to use scale_x_continuous.

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=500)))

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

#plot
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")+
  scale_x_continuous(limits = c(2, 2000),
                     breaks = c(2, 10, 20, 100, 200, 1000, 2000),
                     labels = c(2, 10, 20, 100, 200, 1000, 2000))+
  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")+
  xlab("Irgarol 1051 (ɥg/L)")+ylab("Mortality (%)")+
  theme(axis.text.x = element_text(angle = 90))+
  theme_classic()+
  geom_label_repel(data = data.frame(x = coefs["e"], y = y50),
                 aes(x = x, y = y, label = paste0("LC50 = ", round(x, 2))),
                 hjust = 1, vjust = 1, color = "black", fill = "white", box.padding = 0.5, box.color = NA)+
  theme(legend.title = element_blank())+
  theme(axis.title=element_text(size=15, face='bold'))+
  theme(axis.text.x = element_text(size = 10), axis.text.y = element_text(size = 10))+
  theme(legend.text = element_text(size = 10))

0

There are 0 answers