Search code examples
rplotvegan

Overlaying different species accumulation plots


I want to plot some species accumulation curves in R that can overlay on top of each other in a grey-scale format, whilst being easily interpreted. Here is a link to the type of plot I would like to output, with polygons possessing different types of grey and a degree of transparency, with lines possessing different lty values. Some example data:

df1 <- as.data.frame(matrix(sample(0:1, 3*10, replace=TRUE), ncol=3))
df2 <- as.data.frame(matrix(sample(0:2, 4*10, replace=TRUE), ncol=4))
library(vegan)
spec1 <- specaccum(df1)
spec2 <- specaccum(df2)

Here is as far as I've got with the plot so far (not great example data but the underlying principle holds true):

plot(spec2, ci.type = "polygon", ci.lty = 0, ci.col = "grey")
plot(spec1, ci.type = "polygon", ci.lty = 0, ci.col = "gray50",add= TRUE)

When I try and change lty, it says:

Error in polygon(c(xaxvar, rev(xaxvar)), c(x$richness - ci * x$sd, rev(x$richness + : formal argument "lty" matched by multiple actual arguments.

I am not sure how to overcome this. Any help would be greatly appreciated.


Solution

  • With your data, you need to change the ci.col parameter to an rgb() color specification with an alpha value for transparency (see here for details, -bear in mind that, according to the documentation, the transparency might not be supported in all devices):

    plot(spec2, ci.type = "polygon", ci.lty = 0, ci.col = rgb(0, 0, 0, 0.5))
    plot(spec1, ci.type = "polygon", ci.lty = 1, ci.col = rgb(.5, .5, .5, 0.5),add= TRUE).
    

    This will give you the following plot:

    enter image description here