2

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.

Ming
  • 181
  • 2
  • 10
  • As it stands, this looks like a tool request. While it wasn't hard to find data and plot it, I would suggest you add at least the code you use and when you get stuck to make it a legitimate SO question. – Roman Luštrik Dec 21 '15 at 11:14

1 Answers1

1

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

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • Thanks for your answer. After I dived into what was `ape4`, I got to know there was a `ordihull` in `vegan` package, which can make the circles I need. –  Ming Dec 21 '15 at 20:40
  • Hello, Roman, are you still there? I am using the `ade4`, it is exactly what I wanted. But how to draw `xlab` and `ylab`using the original axis data? –  Ming Jan 08 '16 at 22:12
  • @Ming try experimenting with `axis()`. – Roman Luštrik Jan 08 '16 at 22:43
  • Thanks, Roman, I can draw either `x` or `y` axis using the`axis()`, but still can not edit the `xlab`. As in `plot(...,xlab="PC1",ylab="PC2")`, how to do that since I have generated a plot using `s.class` –  Ming Jan 19 '16 at 06:38
  • @Ming you could try fiddling with `mtext`. – Roman Luštrik Jan 19 '16 at 10:14