0

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))
user20650
  • 24,654
  • 5
  • 56
  • 91
  • 1
    It would be easier to help you with a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data, the basic code you've tried so far, and a clear description of the desired output. – MrFlick Aug 18 '17 at 15:17
  • ##So here is the code I've tried so far## `dayone <- subset(acute, hours==24) 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))` – Frank Green Aug 18 '17 at 15:30
  • And here's the data I'm using [link](https://docs.google.com/spreadsheets/d/1S6TDgwP8wW9Fr7ppyMloCec664xJZ4EXLoM9KGI3saU/edit#gid=0) – Frank Green Aug 18 '17 at 15:32
  • Sorry about the poor formatting of the code in the comment, I'm new to stackoverflow and not sure how to use it quite yet. – Frank Green Aug 18 '17 at 15:37
  • You should edit the question to include this information so it can be properly formatted. Also see the link I provided for how to include data in the question itself rather thank linking externally. – MrFlick Aug 18 '17 at 15:47

1 Answers1

1

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

MrFlick
  • 195,160
  • 17
  • 277
  • 295