[R] add points on an existant ggplot from another dataframe

Arnaud Michel michel.arnaud at cirad.fr
Mon Oct 14 17:27:35 CEST 2013


Hello
I had draw the results of PCA (Principal Components Analysis) (1)
Is it possible to put on this graphic the 75% ellipse confidence of each 
sex calculated by dataEllipse (library(car)) ?

My code is
1) PCA data frame with 169 rows and 2 columns
library(ggplot2)
p <- ggplot(PCA, aes(x=F1, y=F2 ))
p + geom_point(aes(colour = Sexe, shape = Sexe), size=3) +
geom_hline(yintercept = 0) +
geom_vline(xintercept = 0) +
labs(title = "ACP",
x = "Facteur 1", y = "Facteur 2",fill = "Sexe") +
theme(legend.position = c(0.95,0.95),
legend.background = element_rect(colour = "black"))

2) library(car)
XH <- dataEllipse(
X1[ACP$Sexe=="H"],
X2[ACP$Sexe=="H"],
levels=0.75, lty=2, add=TRUE, plot.points=FALSE, center.cex=0, col=4)

XF <- dataEllipse(
X1[ACP$Sexe=="F"],
X2[ACP$Sexe=="F"],
levels=0.75, lty=2, add=TRUE, plot.points=FALSE, center.cex=0, col=2)

XH and XF are two matrix with 2 columns and 52 rows
Thank you for your help

-- 
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31



More information about the R-help mailing list