Search code examples
rvegan

How to draw circle in PCoA results?


enter image description here

I have results with PC1 and PC2 for all the samples, so that I can draw a scatter plot using PC1 as x and PC2 as y.

Now the samples are labeled by another variable, let's say type indicating which sample is case or control. How can I draw a plot as above, with circles covering the responding type.

Actually, I am using vegan package. I can draw a plot with metaMDS and ordiplot, but don't know how to make a circle as above. I have tried to read the tutorial, but still have no idea.


Solution

  • I was able to draw this with ade4.

    xy <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -1, 1))
    posi <- factor(xy$x > 0) : factor(xy$y > 0)
    coul <- c("black", "red", "green", "blue")
    
    library(ade4)
    pca <- princomp(xy)
    s.class(pca$scores[, 1:2], fac = posi, cell = 2, axesell = FALSE, csta = 0, col = coul, clabel = FALSE)
    

    enter image description here