DoseResponse / drc

Fitting dose-response models in R
https://doseresponse.github.io/drc/
21 stars 16 forks source link

Normalization scrambles points and curves #10

Open bjreisman opened 4 years ago

bjreisman commented 4 years ago

Hi there, I'm a big fan of the package. I came across the following issue when using the normal = T option in plot.drc. I've included the following reproducible example.

Plotting the unnormalized data works just fine:

library(drc)
mydata <- read.csv("repex.csv")
drc.model <-  drm(abs ~ conc, drug, data = mydata, fct = LL.4())
plot(drc.model, 
     type = "average",
     normal = F, 
     col = T, 
     broken = T, 
)

image

...but when I set the normal option to TRUE, the points for labels and curves for Ap Am appear to be mismatched. The curves are correct, but the points are misplotted

plot(drc.model, 
     type = "average",
     normal = T, 
     col = T, 
     broken = T, 
)

image

Setting type = "bars" also seems to normalize the curves, but not the error bars:

plot(drc.model, 
     type = "bars",
     normal = T, 
     col = T, 
     broken = T, 
)

image

The first issue can be corrected by sorting the data alphabetically first., but in a fix it would be desirable to control the order of the points in the legend.

Happy to contribute to a potential fix. 🤓

bjreisman commented 4 years ago

repex.zip Whoops, forgot to include the data used to generate these plots.