1 Vegetation Analysis. 2 ## 1.1 Calculate the total basal area by species. Show a bar plot of the...

3
1 Vegetation Analysis

Transcript of 1 Vegetation Analysis. 2 ## 1.1 Calculate the total basal area by species. Show a bar plot of the...

Page 1: 1 Vegetation Analysis. 2 ## 1.1 Calculate the total basal area by species. Show a bar plot of the sorted values. spbatot

1

Vegetation Analysis

Page 2: 1 Vegetation Analysis. 2 ## 1.1 Calculate the total basal area by species. Show a bar plot of the sorted values. spbatot

2

## 1.1 Calculate the total basal area by species. Show a bar plot of the sorted values.

spbatot <- apply(spba, 2, sum)

barplot(sort(spbatot), cex.names=0.5)

## 1.2 Calculate the average basal area per plot by species. Hint: use the table created from 1.1 and the sppres table. Show a bar plot of the sorted values with labels.

sppres ## Display sppresspbaavg <- round(spbatot / sppres, 2) ## Average basal area for each species

barplot(sort(spbaavg), cex.names=0.5, main="Avg basal area by species", xlab="Species", ylab="Avg basal area per

plot")

## 1.3 Compare the barplot of avg basal area per plot with the barplot of avg number of trees per plot. Do not sort tables. Show on the same page and label plots. Hint: use par(mfrow).

par(mfrow=c(2,1))barplot(spbaavg, cex.names=0.5, main="Avg basal area per plot by species",

xlab="Species", ylab="Avg basal area per plot")barplot(spavg, cex.names=0.5, main="Avg number of trees per plot by species",

xlab="Species", ylab="Avg number of trees per plot")

## 1.4 Which species has the highest basal area per plot?Utah juniper

## 1.5 Which species has the highest number of trees per plot?mahogany

Exercise 1 Answers

Page 3: 1 Vegetation Analysis. 2 ## 1.1 Calculate the total basal area by species. Show a bar plot of the sorted values. spbatot

3

## 1.6 Append the spba table to the plt table, naming the new object plt3. Change any NA values to 0 values. Make sure all records of plt are included.

plt3 <- merge(plt, spba, by.x="CN", by.y="row.names", all.x=TRUE)head(plt3)dim(plt3)spnames <- colnames(spba)plt3[,spnames][is.na(plt3[,spnames])] <- 0 # Change NA values to 0head(plt3)

## 1.7 Append the totba vector to the plt3 data frame, keeping plt3 as the name. Change any NA values in new column to 0 values. Make sure all records of plt3 are included.totba.df <- data.frame(totba)plt3 <- merge(plt3, totba.df, by.x="CN", by.y="row.names", all.x=TRUE)head(plt3)dim(plt3)plt3[,"totba"][is.na(plt3[,"totba"])] <- 0 # Change NA values to 0head(plt3)

## 1.8 Merge the species-level tables created in 1.1 and 1.2 (spbatot, spbaavg) to the sptab table.sptabis.vector(spbatot)is.vector(spbaavg)spbatot.df <- data.frame(spbatot)spbaavg.df <- data.frame(spbaavg)sptab <- merge(sptab, spbatot.df, by.x="Species", by.y="row.names")sptab <- merge(sptab, spbaavg.df, by.x="Species", by.y="row.names")sptab

Exercise 1 Answers