Search code examples
rpcavegan

Specifying and plotting PCA site symbols according to zone


I'm creating a PCA in the example below, I know to to get the plot to vary the symbol according to another variable (I've just used a set of zones from 1 to 5 for example).

I would like to know how to also specify the plotting symbol for each zone as I don't like the default.

Here's my example:

## load vegan

require("vegan")

## load the Dune data
data(dune)

## run pca
dune_pca <- rda(dune)

## create zones for e.g. 
zone <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5)

## plot blank PCA and add sites with 
## symbol varying accoring to zone
plot(dune_pca, type = "n", scaling = 3)
points(dune_pca, display = "sites", scaling = 3, pch = zone)

Solution

  • I would make a vector of the characters I want and then subset this by zone

    zone_pch <- c(16, 10, 3, 8, 2)
    plot(dune_pca, type = "n", scaling = 3)
    points(dune_pca, display = "sites", scaling = 3, pch = zone_pch[zone])