I need to make some rarefaction curves and I wish them to display the whiskers at the edges of the confidence interval bars, whereas the default is to simply display the bars without whiskers:
library(vegan)
data("dune")
result <- specaccum(dune)
plot(result, lwd=2)
I've tried to add some whiskers using the arrows
function, but the results from the specaccum
function only include the standard deviation. So I ended up with half the job done:
samples <- result$sites
error <- result$sd
richness <- result$richness
arrows(samples, richness-error, samples, richness+error, angle=90, code=3, length=0.05)
From what I've searched, the most common approach would be to convert the confidence intervals into a shaded area (by using the argument ci.type="polygon"
) and then add a boxplot
to the plotted curve. However, this leads to a very busy image that I'd rather avoid.
Does anyone have a more elegant solution?
You forgot the multiplier (see argument ci
in ?plot.specaccum
). What you drew were for a ~68% confidence interval. Multiplying by 2 (ci = 2
) gives an approximate 95% confidence interval, which is what plot.specaccum
draws by default.
Including the (default) multiplier in a modification of the code you used
plot(result)
with(result, arrows(sites, richness - (2 * sd), sites, richness + (2 * sd),
angle = 90, code = 3, length = 0.05))
we get:
You can ignore the warning; the standard error of the last data point drawn is zero
> result$sd
[1] 2.3510636 1.8763851 1.5722711 1.4469584 1.3901594 1.3530349 1.3164796
[8] 1.2749034 1.2282010 1.1763410 1.1193437 1.0564537 0.9874094 0.9115998
[15] 0.8286890 0.7380921 0.6333903 0.5139710 0.3570714 0.0000000
and arrow()
is just warning you that it won't draw a length 0 arrow.