Re: [R] draw circle on PCA plot

2009-11-26 Thread Wai Kuan Yip

Phoebe,

Hi, this was how I solved that problem using plot(). I found using symbols
to be hard to adjust... 

#plot the 1st vs 2nd component
plot(x,y,ylab=2nd component, xlab=1st component, xlim=range(x),
ylim=range(y), main=1st vs 2nd component analysis)
#show the arrows, length defined by the 1st and 2nd compoentns
arrows(0,0,ePCAMat$vector[1,]*max(x),ePCAMat$vector[2,]*max(y),length=0.1,
angle=20, col=red)
text(ePCAMat$vector[1,]*max(x)*1.1, ePCAMat$vector[2,]*max(y)*1.1,
names(label), col=red,cex=0.5)

#THIS IS THE PART TO DO THE PLOTTING OF CIRCLES
#You need to calculate the center of each class cluster beforehand 
for(i in 1:noClass){
   par(new=T)
   #specify the center x,y coordinate and then cex = radius  
   plot(center[i,1],center[i,2],ylab=,
xlab=,xlim=range(x),ylim=range(y),pch=1,cex=mean(distances[i,]),col=(i+1))
  
}


--
Wai-Kuan YIP

http://www.deakin.edu.au/~waiyip http://www.deakin.edu.au/~waiyip 



phoebe kong wrote:
 
 Hi,
 
 I have a hard time in drawing circle on PCA.
 I have 60 samples. The corresponding PC1 scores and PC2 scores were stored
 as mergedata. Here are the summary of PCs scores.
 
 range(mergedata[,PC1])
 [1] 0.0085 0.0100
 range(mergedata[,PC2])
 [1] 0.0032 0.0075
 mean(mergedata[,PC1])
 [1] 0.009241667
 mean(mergedata[,PC2])
 [1] 0.005541667
 dim(mergedata)
 [1]  60 102
 First of all, I need to find the center of the cluster points in PC plot.
 Then, I would lilke to draw out from that center concentric circles with
 radius 1 SD, 1.5 SD, 2 SD, 2.5 SD and 3 SD.
 
 plot(mergedata[,PC1],mergedata[,PC2],xlab=PC1,ylab=PC2,xlim=range(mergedata[,PC1]),ylim=range(mergedata[,PC2]),pch=20,col=blue)
 circle with radius 1SD
 symbols(mean(mergedata[,PC1]),mean(mergedata[,PC2]),circle=sd(c(mergedata[,PC2],mergedata[,PC1])),inches=FALSE,add=TRUE)
 
 
 However, only points were plotted, but the cicle doesn't appear. Could
 anyone tell me what's wrong with my code?
 
 Thanks,
 Phoebe
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://old.nabble.com/draw-circle-on-PCA-plot-tp26517726p26535850.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] draw circle on PCA plot

2009-11-25 Thread phoebe kong
Hi,

I have a hard time in drawing circle on PCA.
I have 60 samples. The corresponding PC1 scores and PC2 scores were stored
as mergedata. Here are the summary of PCs scores.

 range(mergedata[,PC1])
[1] 0.0085 0.0100
 range(mergedata[,PC2])
[1] 0.0032 0.0075
 mean(mergedata[,PC1])
[1] 0.009241667
 mean(mergedata[,PC2])
[1] 0.005541667
 dim(mergedata)
[1]  60 102
First of all, I need to find the center of the cluster points in PC plot.
Then, I would lilke to draw out from that center concentric circles with
radius 1 SD, 1.5 SD, 2 SD, 2.5 SD and 3 SD.

plot(mergedata[,PC1],mergedata[,PC2],xlab=PC1,ylab=PC2,xlim=range(mergedata[,PC1]),ylim=range(mergedata[,PC2]),pch=20,col=blue)
circle with radius 1SD
symbols(mean(mergedata[,PC1]),mean(mergedata[,PC2]),circle=sd(c(mergedata[,PC2],mergedata[,PC1])),inches=FALSE,add=TRUE)


However, only points were plotted, but the cicle doesn't appear. Could
anyone tell me what's wrong with my code?

Thanks,
Phoebe

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.