Search code examples
rdrc

How to add ED function output from the console to a DRM plot


Within the DRC Package, I am trying to add the output that I get from running the ED function into a text box that I have placed on my DRM plot. Any ideas on how to write the script so that I can include the ED function in the text function and automatically place the results onto the plot?

Here is the code I've tried so far:

dayone <- structure(list(hours = c(24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 
    24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 
    24L, 24L, 24L, 24L, 24L, 24L, 24L), jarnum = c(NA_character_, 
    NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
    NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
    NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
    NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
    NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
    NA_character_, NA_character_), treat = c(0L, 0L, 0L, 0L, 1500L, 
    1500L, 1500L, 1500L, 3000L, 3000L, 3000L, 3000L, 4000L, 4000L, 
    4000L, 4000L, 5000L, 5000L, 5000L, 5000L, 6000L, 6000L, 6000L, 
    6000L, 10000L, 10000L, 10000L, 10000L), rep = c(1L, 2L, 3L, 4L, 
    1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 
    1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), total = c(5L, 5L, 5L, 5L, 5L, 
    5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
    5L, 5L, 5L, 5L, 5L, 5L, 5L), mort = c(0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 
    5L, 5L, 5L, 5L, 5L, 5L), cummort = c(0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 
    5L, 5L, 5L, 5L, 5L, 5L)), .Names = c("hours", "jarnum", "treat", 
    "rep", "total", "mort", "cummort"), row.names = c(NA, -28L), class = c("tbl_df", 
    "tbl", "data.frame"))

drmdayone <- drm(cummort/total~treat, data=dayone, fct=LL.2(), type="binomial")
plot(drmdayone, type="all", pch=16, lwd=2,log="x", main="Acute DRC - 24 Hours",xlab="[Cl-] (mg/L)", ylab="Mortality", axes=F) 
axis(1, c(1500,3000,4000,5000,6000,10000))
axis(2, c(0,0.1,0.5,1))
text(500, 0.6, "Here is where I want the ED function (below) results to be displayed", font=2)

ED(drmdayone, c(10,50,90))

Solution

  • Not sure exactly how you want it to look, but you can capture the text output from the function and draw it directly.

    text(500, .9, paste(capture.output(ED(drmdayone, c(10,50,90))), collapse="\n"))
    

    enter image description here