# NOT RUN {
require(graphics)
############################
## Some "type (1)" plots ##
############################
data(solberg)
solbdat <- solberg$abund
treatment<- solberg$x
## Plot a multivariate dataset (Species vs Abundance)
plot.mvabund(solbdat)
## Alternatively, the plot command could be used directly if spiddat is
## defined as an mvabund object:
solbmvabund <- mvabund(solbdat)
plot(solbmvabund)
## Draw an mvabund object in a boxplot, but using the 20 most abundant
## variables in the plot, using the square root transform, and adding
## coloured axes and title:
plot.mvabund(solbdat, n.vars=20, type="bx", transformation="sqrt",
fg="lightblue", main="Solberg abundances", col.main="red")
## Plot Species (split by treatment) vs Abundance
plot(solbmvabund,treatment)
## This can also be produced using
plot(solbmvabund~treatment)
## To use plot.mvabund to plot only the variables with P-values less than 0.1:
lm.solberg <- manylm(log(solbmvabund+1)~treatment)
anova.solb <- anova(lm.solberg, p.uni="unadjusted")
pj = anova.solb$uni.p
plot(solbmvabund~treatment, var.subset=pj<0.1)
## Or to plot only the 12 most significant variables, according to their
## univariate ANOVA P-values:
pj.sort = sort(pj, index.return=TRUE)
plot(solbmvabund~treatment, var.subset=pj.sort$ix[1:12])
############################
## Some "type (2)" plots ##
############################
#load and convert data
data(spider)
spiddat <- mvabund(spider$abund)
spidx <- mvabund(spider$x)
#create labels vectors
pch.vec <- as.numeric(spidx[,3]<2)
pch.vec[pch.vec==0] <- 3
#Scale the soil water variable
soilWater <- spidx[,1]
#Create the Table for the main titles of each plot
title <- c("\n\nAlopecosa accentuata", "\n\nAlopecosa cuneata",
"\n\nAlopecosa fabrilis", "\n\nArctosa lutetiana",
"\n\nArctosa perita", "\n\nAulonia albimana",
"\n\nPardosa lugubris", "\n\nPardosa monticola",
"\n\nPardosa nigriceps", "\n\nPardosa pullata",
"\n\nTrochosa terricola", "\n\nZora spinimana")
#Plot Species Abundance vs Environmental variable
plot.mvformula(log(spiddat+1) ~ exp(soilWater), main=title,
xlab="% Soil Moist - Log Scale ", ylab="Abundance [log scale]",
overall.main="Species Abundance vs %Soil Moisture", col=pch.vec,
fg="grey", pch=pch.vec, las=1, scale.lab="ss",t.lab="o", mfrow=c(4,3),log="x")
#Add a Margin
par(xpd=NA)
legend("topright",pch=c(1,3),col=c(1,3),legend = c("few twigs", "many twigs"),
cex = 1, inset=c(0,-0.19))
############################
## Some "type (3)" plots ##
############################
##Plot 1981 Abundance vs 1983 Abundance
data(tikus)
year <- tikus$x[,1]
tikusdat <- mvabund(tikus$abund)
site <- tikus$x[,2]
plot(tikusdat[year==81,], tikusdat[year==83,], col.main="blue",
xlab="1981 abundance", ylab="1983 abundance")
# }
Run the code above in your browser using DataLab