Error in plotting dose-response curve in ggplot with drc package

352 Views Asked by At

I'm getting a half plotted graph when trying to plot the dose-response curve using ggplot in drc package. I'm trying to follow procedure given in a suplementary information from a recent paper on dose response curve. Here is my raw data

raw data

Please help me to find solution, thanks!

# Fit a log-logistic model with lower and upper asymptotic limits fixed at respectively 0 and 100

mod.Pyr <- drm(gi ~ conc, data = my_data, fct = LL.4(fixed = c(NA, 0, 100, NA)))

# new dose levels as support for the line

newdata <- expand.grid(conc=exp(seq(log(0.5), log(3000), length=1000)))

# predictions and confidence intervals

pm <- predict(mod.Pyr, newdata=newdata, interval="confidence")

# new data with predictions

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

# need to shift conc == 0 a bit up, otherwise there are problems with coord_trans

my_data$conc0 <- my_data$conc
my_data$conc0[my_data$conc0 == 0] <- 0.5

# plotting the curve

ggplot(my_data, aes(x = conc0, y = gi)) +
  geom_point() +
  geom_ribbon(data=newdata, aes(x=conc, y=p, ymin=pmin, ymax=pmax), alpha=0.2) +
  geom_line(data=newdata, aes(x=conc, y=p)) +
  coord_trans(x="log") +
  xlab("Concentration (mg/l)") + ylab("Growth inhibition")

enter image description here

1

There are 1 best solutions below

1
On BEST ANSWER

You have conc values above log(3000) and you only created newdata for values until log(100) so you're not able to fit until log(3000), you just need to increase log(100) in expand.grid to higher values, examples with log(3000) :

newdata <- expand.grid(conc=exp(seq(log(0.5), log(3000), length=100)))

enter image description here