These lines works fine when in a function in an R-script:
hline_DL <- 22
p <- p + geom_hline(aes(yintercept=hline_DL), color="red", linetype=2)
But when I create a package with the same identical function inside (copy paste!), I get this fault when running the function:
"Error in eval(expr, envir, enclos) : object 'hline_DL' not found"
If I take away the rows above, then the rest of the function works well in the package (plotting what I want, but without the dashed horizontal line at y=22).
Why is it working as a standalone function, and not in a package? How can I fix it?
Apparently, my suggestion worked. Namely, put
yintercept = hline_DLoutside ofaes(), to avoid the non-standard evaluation taking place.In general, aesthetics that are set to a single value should not be set inside
aes()anyway.