2

データサブセットの pca バイプロットを作成しようとしています。同じ主成分環境内で、水分レベルに基づいてサブセットのみをプロットしたいと思います。

# Packages
library(vegan)

# Sample data
data(dune, dune.env)
dd <- cbind(dune.env, dune)

# Runnig PCA
pca1 <- rda(dd[, -c(1:5)], scale=T)

# Plot
plot(pca1, scaling=3)

# Now, instead the plot above, I'd like to get 5 different plots (one per dd$Moisture level) where I see the principal components scores but only for the subsets based on:
levels(dd$Moisture)

ご意見をお寄せいただきありがとうございます。

4

2 に答える 2

0
# Packages
library("vegan")

# Preparing data
data(dune, dune.env)
dd <- cbind(dune.env, dune)
# Order data frame based on dd$Moisture
dd <- dd[order(dd$Moisture),]
str(dd)

# Runnig PCA
pca1 <- rda(dd[, -c(1:5)], scale=T)

# Plot
biplot(pca1, scaling=3, type = c("text", "points"))

# I need to get 5 different plots (one per dd$Moisture level)
# grab the scores on axes required
site.scr <- scores(pca1, display = "sites", scaling = 3) # x
spp.scr <- scores(pca1, display = "species", scaling = 3) # y

## generate x,y lims
xlims <- range(site.scr[,1], spp.scr[,1])
ylims <- range(site.scr[,2], spp.scr[,2])

## plot what you want, but leave out sites
biplot(mod, display = "species", 
       xlim=xlims, ylim=ylims, 
       scaling = 3)

## now add in scores as you want, to simulate we plot:
# Moisture - All together but can be in independetn plots
points(site.scr[1:7,], col = "blue", pch = 2)
points(site.scr[8:11,], col = "green", pch = 2)
points(site.scr[0:0,], col = "orange", pch = 2) # Level 3 not present
points(site.scr[12:13,], col = "grey", pch = 2)
points(site.scr[14:20,], col = "black", pch = 2)
于 2014-06-17T11:49:31.243 に答える