I know how to use the PCA results to draw the circle, but failed to draw the x.lab
and the y.lab
based on the plotting results from s.class
.
How to make a plot as I posted here? I would like to ask more about this.
How to make the points bigger or smaller according to another integer variable?
Can ggplot2
draw the same circle as s.class
? The previous answers do not show how to draw circles.
Hi, In the PCA plot, right click on the graph and select "ROW LEGEND", you can then choose the column that will be used to color code the dots on your plot.
The size of the points cane adjusted using size. The ellipses can be added via stat_ellipsis
pca <- prcomp(iris[iris$Species %in% c("virginica","versicolor"),1:4], retx = TRUE, scale = TRUE,tol=0.4)
predicted <-predict(pca,iris[,1:4])
ggplot(data.frame(predicted))+aes(x=PC1,y=PC2,color=iris$Species)+geom_point(aes(size=iris$Sepal.Length))+stat_ellipse()+stat_ellipse(level=0.8)
What I did in the pcoa
function of my msap
package was to use s.class
only for the ellipses and centroids:
Add empty plot, with labels and limits depending on several variables:
plot(0,0, main=paste(name,surname, sep=": "), type = "n",
xlab=paste("C1 (",var1,"%)"),ylab=paste("C2 (",var2,"%)"),
xlim=c(minX-10^floor(log10(abs(minX))),maxX+10^floor(log10(abs(maxX)))),
ylim=c(minY-10^floor(log10(abs(minY))),maxY+10^floor(log10(abs(maxY)))),
frame=TRUE, cex=1.5)
Look at the xlab.
Plot the points for the different treatments/groups with different colors/simbols. Here you could set the points size using the cex parameter.
for(i in 1:ntt){
points(spcoo[[i]], pch=21, col="black", bg=bgcolors[i])
}
Finally use ade4's c.class to plot ellipses, stars and group labels, but not the points (cpoint=0)
s.class(pcol$points, groups, cpoint=0, col=bgcolors, add.plot=TRUE)
In my code I get a figure like this PCOA figure:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With