library(dplyr)
head(edidiv) tail(edidiv) str(edidiv) dim(edidiv) summary(edidiv)
Beetle <- filter(edidiv, taxonGroup == “Beetle”) Bird <- filter(edidiv, taxonGroup == “Bird”) Butterfly <- filter(edidiv, taxonGroup == “Butterfly”) Dragonfly <- filter(edidiv, taxonGroup == “Dragonfly”) Flowering.Plants <- filter(edidiv, taxonGroup == “Flowering.Plants”) Fungus <- filter(edidiv, taxonGroup == “Fungus”) Hymenopteran <- filter(edidiv, taxonGroup == “Hymenopteran”) Lichen <- filter(edidiv, taxonGroup == “Lichen”) Liverwort <- filter(edidiv, taxonGroup == “Liverwort”) Mammal <- filter(edidiv, taxonGroup == “Mammal”) Mollusc <- filter(edidiv, taxonGroup == “Mollusc”)
a <- length(unique(Beetle\(taxonName)) b <- length(unique(Bird\)taxonName)) c <- length(unique(Butterfly\(taxonName)) d <- length(unique(Dragonfly\)taxonName)) e <- length(unique(Flowering.Plants\(taxonName)) f <- length(unique(Fungus\)taxonName)) g <- length(unique(Hymenopteran\(taxonName)) h <- length(unique(Lichen\)taxonName)) i <- length(unique(Liverwort\(taxonName)) j <- length(unique(Mammal\)taxonName)) k <- length(unique(Mollusc$taxonName))
biodiv <- c(a,b,c,d,e,f,g,h,i,j,k) names(biodiv) <- c(“Beetle”, “Bird”, “Butterfly”, “Dragonfly”, “Fl.Plants”, “Fungus”, “Hymenopteran”, “Lichen”, “Liverwort”, “Mammal”, “Mollusc”)
barplot(biodiv)
help(barplot) help(par)
png(“barplot.png”, width=950, height=500) barplot(biodiv, xlab=“Taxa”, ylab=“Number of species”, ylim=c(0,600), cex.axis=1.5, cex.lab=1.5) dev.off() # The plot has been saved in your working directory # To confirm where that was, you can use getwd(), and to change it, you can use setwd() getwd()
taxa <- c(“Beetle”, “Bird”, “Butterfly”, “Dragonfly”, “Fl.Plants”, “Fungus”, “Hymenopteran”, “Lichen”, “Liverwort”, “Mammal”, “Mollusc”) taxa_f <- factor(taxa) richness <- c(a,b,c,d,e,f,g,h,i,j,k) biodata <- data.frame(taxa_f, richness) write.csv(biodata, file=“biodata.csv”)
png(“barplot2.png”, width=950, height=500) barplot(biodata$richness, names.arg=c(“Beetle”, “Bird”, “Butterfly”, “Dragonfly”, “Fl.Plants”, “Fungus”, “Hymenopteran”, “Lichen”, “Liverwort”, “Mammal”, “Mollusc”), xlab=“Taxa”, ylab=“Number of species”, ylim=c(0,600), cex.axis=1.5, cex.lab=1.5) dev.off()