User Tools

Site Tools


en:pca_rscript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:pca_rscript [2018/04/14 19:57] (current)
David Zelený created
Line 1: Line 1:
 +<code rsplus>
 +# PCA on Trebic grasslands - biplots with two different scalings
 +grasslands.spe <- read.delim ('​https://​raw.githubusercontent.com/​zdealveindy/​anadat-r/​master/​data/​grasslands-spe.txt',​ row.names = 1)
 +grasslands.env <- read.delim ('​https://​raw.githubusercontent.com/​zdealveindy/​anadat-r/​master/​data/​grasslands-env.txt'​)
  
 +library (vegan)
 +library (RColorBrewer)
 +
 +cols <- brewer.pal (6, '​Dark2'​)
 +
 +PCA <- rda (log1p (grasslands.spe))
 +groups <- as.numeric (grasslands.env$classification)
 +
 +png ('​pca_grasslands.png',​ width = 8, height = 4, units = '​in',​ res = 300, pointsize = 10)
 +par (mfrow = c(1,2))
 +biplot (PCA, display = '​sites',​ scaling = '​species',​ type = '​n',​ main = '​Grasslands dataset: sample scores\n(scaling = 1, focus on sites)'​)
 +points (PCA, display = '​sites',​ pch = as.character (groups), scaling = '​species',​ col = cols[groups])
 +biplot (PCA, display = '​species',​ scaling = '​species',​ main = '​Grasslands dataset: species scores\n(scaling = 2, focus on species)'​)
 +dev.off ()
 +</​code>​
en/pca_rscript.txt · Last modified: 2018/04/14 19:57 by David Zelený