【问题标题】:Error in plotting dose-response curve in ggplot with drc package使用 drc 包在 ggplot 中绘制剂量反应曲线时出错
【发布时间】:2021-09-21 11:34:26
【问题描述】:

在尝试使用 drc 包中的 ggplot 绘制剂量反应曲线时,我得到了一个半标图。我正在尝试遵循剂量反应曲线上recent paper 的补充信息中给出的程序。 这是我的原始数据

请帮我找到解决办法,谢谢!

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

【问题讨论】:

    标签: r ggplot2 drc


    【解决方案1】:

    您的conc 值高于log(3000),并且您只为log(100) 之前的值创建了newdata,因此直到log(3000) 才能适应,您只需要在展开中增加log(100)。网格到更高的值,log(3000) 的示例:

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

    【讨论】:

    • 非常感谢,它有效。我想知道是否可以在 1000 之前在 x 轴上包含更多数据点,例如 10 和 100,以便图表更具可读性。此外,如果由于第一个浓度为 100 mg/l,可以将图形向 y 轴挤压,那么在此之前会占用大量空间,我需要并排包含七个图形。请让我知道这是否可能。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    • 2017-11-24
    • 1970-01-01
    相关资源
    最近更新 更多