lakes <- read.csv("https://tpetzoldt.github.io/datasets/data/lakes-combined-data.csv")
valid_columns <- c("name", "shortname", "z_mean", "z_max", "t_ret", "volume",
"area", "p_tot", "n_no3", "chl", "wfd_type")
# set row names and limit data set to complete records without missing data
row.names(lakes) <- lakes$shortname
lakes <- na.omit(lakes[valid_columns])
# only the numerical variables
lakedata <- lakes[c("z_mean", "z_max", "t_ret", "volume",
"area", "p_tot", "n_no3", "chl")]
## PCA with the vegan package
library("vegan")
lakedata2 <- sqrt(lakedata)
pc <- rda(lakedata2, scale = TRUE)
summary(pc)
biplot(pc)
biplot(pc, choices=c(3, 2))
## 3D Plot
library("vegan3d")
ordirgl(pc, col = "yellow")
orgltext(pc, display = "species", col="red")
orgltext(pc, display = "sites", col="blue", pos=4)
view3d(theta = 5, phi = 15, fov=30, zoom=1)
## NMDS
md <- metaMDS(lakedata2, scale = TRUE, distance = "euclid", trace=FALSE)
plot(md, type="text")
abline(h=0, col="grey", lty="dotted")
abline(v=0, col="grey", lty="dotted")