2

I would plot points of a metaMDS using different symbols. I would categorize the sites and plot it as points with different symbols.

I have 89 sites and I would group them in 11 groups and then plot it.

Do you have any idea how can I do this?

Thank you very much.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
alexmulo
  • 751
  • 4
  • 11
  • 23
  • 2
    There is a `points` method for `metaMDS` objects which you'll want to use for this. This is a **vegan** FAQ, and Gavin Simpson (one of **vegan**'s authors) has [a nice post here](http://ucfagls.wordpress.com/2012/04/11/customising-vegans-ordination-plots/#more-437) that'll probably help you more than any answer here could. – Josh O'Brien May 06 '13 at 12:54
  • @JoshO'Brien I'd consider that a postable answer. – Carl Witthoft May 06 '13 at 13:14
  • I added a short version of my blog post as an answer, mainly so I could illustrate how you'd do this using **ggplot** via the new **ggvegan** package. – Gavin Simpson May 10 '13 at 15:12

1 Answers1

3

Here is a simple example using base plots in vegan. There is more detail in my blog post on the subject. The key is to create a set of plotting characters for the 11 groups (pchs below) and then index that set of characters using a factor containing the group membership (grps below).

require("vegan")
data(dune)

set.seed(123)
sol <- metaMDS(dune)

pchs <- 1:11
grps <- factor(sample(LETTERS[1:11], nrow(dune), replace = TRUE))
## note that not all 11 groups are included in this sample
## but this is just for show - you will have a variable containing
## the group membership data

plot(sol, type = "n", display = "sites")
points(sol, display = "sites", pch = pchs[grps])

If you want more automation and are happy to use the ggplot2 package, I have started a new package, ggvegan which will do this for you. ggvegan is not on CRAN or R-forge at the moment so you'll need to build the package yourself or install it using tools from the devtools package.

require("ggvegan")
scrs <- fortify(sol)
scrs <- subset(scrs, subset = Score == "sites")
## ggplot doesn't like more than 6 groups for shape
grps <- factor(sample(LETTERS[1:6], nrow(dune), replace = TRUE))
scrs <- cbind(scrs, Group = grps) ## add on the group variable

## do the plot
ggplot(scrs, aes(x = Dim1, y = Dim2, shape = Group, colour = Group)) + 
  geom_point() + coord_fixed()

For more than six groups you need to specify the shapes by hand, via a scale but that is beyond the scope of this Answer.

It is early days for ggvegan and I may well make the fortify methods accept additional vectors to add to the fortified scores, but for now you have to add the grouping variable yourself.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453