[R-sig-eco] (no subject)

Ellen Pape ellen@p@pe @ending from gm@il@com
Mon Dec 17 17:13:57 CET 2018


Hi all,

As I use ggplot2 for all my graphs, I would like to use ggplot2 to
construct rarefaction curves as well (I also want to combine 2 rarefaction
curves in 1 plot using cowplot which also vows for using ggplot2).

I made these rarefaction curves using the rarecurve function in vegan, but
I don't see how I can use these results and put these in ggplot2.

I found the following website during my search:
https://www.fromthebottomoftheheap.net/2015/04/16/drawing-rarefaction-curves-with-custom-colours/
but it does not explain how to draw rarefaction curves with ggplot2.

This website mentions - and this is what I would like to be able to do in
ggplot2:

"Where I do think this sort of approach might work is if the samples in the
data set come from a few different groups and we want to colour the curves
by group.

col <- c("darkred", "forestgreen", "hotpink", "blue")set.seed(3)grp <-
factor(sample(seq_along(col), nrow(BCI2), replace = TRUE))cols <-
col[grp]

The code above creates a grouping factor grp for illustration purposes; in
real analyses you'd have this already as a factor variable in you data
somewhere. We also have to expand the col vector because we are plotting
each line in a loop. The plot code, reusing elements from the previous
plot, is shown below:

plot(c(1, max(Nmax)), c(1, max(Smax)), xlab = "Sample Size",
     ylab = "Species", type = "n")abline(v = raremax)for (i in seq_along(out)) {
    N <- attr(out[[i]], "Subsample")
    lines(N, out[[i]], col = cols[i])}

[image: An attempt at rarefaction curves output with custom colours per
groups of curves.]An attempt at rarefaction curves output with custom
colours per groups of curves.


but I don't see how I adjust this code to make the same plot in ggplot2.



Anyone?

Thanks!
Ellen

	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list