Arne Erpenbach
unread,Oct 15, 2012, 8:22:24 AM10/15/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplot2
Hi all,
has anyone out there plotted 'specaccum' and 'fitspecaccum' objects from
{vegan} with ggplot2 and would be willing to share some experience (and
code)?
I am posting some examples below, including a plot via
plotspecaccum{BiodiversityR} which I would like to rebuild in ggplot2.
Cheers,
a+
################################################################
library(vegan)
data(dune.env)
data(dune)
acc <- specaccum(dune, method="random", permutations=2)
# Low nr. of permutations just to check the structure!
str(acc)
# adds arrhenius (power) models to the randomized SACurves:
mod <- fitspecaccum(acc, "arrh")
class(mod)
str(mod) # very complicated stucture!
# plots the specaccum-object:
plot(acc)
# plots the nlm's:
plot(mod, col=rgb(255,0,0,50, maxColorValue=255), add=TRUE)
# gives number of model with best AIC:
best <- which((sapply(mod$models, AIC)) == min(sapply(mod$models, AIC)))
# summarizes the best model, including k and z values.
mod$models[best]
############################################################
# Plotting a single nl-model from fitspeccaccum{vegan} is complictated,
# this is only a quick-and-dirty workaround:
# (first, include more permutations!)
acc <- specaccum(dune, method="random", permutations=100)
mod <- fitspecaccum(acc, "arrh")
plot(acc)
plot(mod, col=rgb(0,0,255,20, maxColorValue=255), add=TRUE)
best <- which((sapply(mod$models, AIC)) == min(sapply(mod$models, AIC)))
# workaround to get the best model out of the object:
# recycle, to get a plottable object of the class speccacum:
workaround <- acc
# replace y-values with model fit:
workaround$richness <- mod$fitted[,best]
plot(workaround, col=rgb(255,0,0,150, maxColorValue=255), add=TRUE)
#### Some plots I'd like to rebuild using ggplot2:
plot(acc, ci.type="polygon", col=rgb(1,1,1), lwd=1, ci.lty=0,
ci.col=rgb(150,150,180,127, maxColorValue=255))
plot(workaround, add=TRUE, col=rgb(255,0,0,50, maxColorValue=255), lwd=2)
plot(workaround, ci.type="polygon", col=rgb(1,1,1), lwd=1, ci.lty=0,
ci.col=rgb(1,1,1,70, maxColorValue=255), add=TRUE)
mod$models[best]
# Side problem: how to access z-values from the object?
str(mod$models[best]) # It's a list!
#######################################################
################################################################################
# Approach of data handling using factors which I need to rebuild:
library(BiodiversityR)
accumcomp(dune, y=dune.env, factor="Management", method="exact",
permutations=100)
################################################################################