PCA/R/make_plot.R

option = readline(prompt = 'which plot you want ? Please type')





PR1=c(-1.47404801, -1.23022158, -0.82478829, -0.47174389 ,-0.06228338,  0.38073067 , 0.79820996
      ,1.16294349 , 1.45273613  ,1.55822568 , 1.55822568  ,1.45273613 , 1.16294349 , 0.79820996
      ,0.38073067 ,-0.06228338 ,-0.47174389 ,-0.82478829, -1.23022158 ,-1.47404801 , 1.93785991
      ,0.98815162,  0.16907760 ,-0.37158738 ,-1.34641851, -1.92018868 )

PR2=c( 1.224006e+00,  1.472994e+00  ,1.628937e+00 , 1.689646e+00,  1.651476e+00,  1.512204e+00 , 1.282158e+00 , 9.752109e-01
       ,6.096384e-01 , 2.073640e-01, -2.073640e-01, -6.096384e-01 ,-9.752109e-01, -1.282158e+00 ,-1.512204e+00, -1.651476e+00
       ,-1.689646e+00 ,-1.628937e+00, -1.472994e+00 ,-1.224006e+00,  2.541772e-15 , 4.071885e-16 , 1.220930e-16 ,-2.910277e-16
       ,-4.728641e-16 ,-9.100274e-16)

PC1=c( -1.56950250, -1.55775290 ,-1.03932366, -0.97360853, -0.86146823, -0.57675171 , 0.09298783,  0.39811322 , 0.69352919 , 0.94228431
       ,1.12303486 , 1.57801755 , 1.57801755,  1.12303486,  0.94228431,  0.69352919,  0.39811322 , 0.09298783, -0.57675171 ,-0.86146823
       ,-0.97360853 ,-1.03932366 ,-1.55775290 ,-1.56950250)

PC2=c(0.4115058 , 0.7253764 , 0.9695751,  1.1556655  ,1.2888170 , 1.3372625 , 1.3051833,  1.1952932 , 1.0137462,  0.7709940 , 0.4819382 , 0.1639310
      ,-0.1639310 ,-0.4819382 ,-0.7709940, -1.0137462 ,-1.1952932, -1.3051833, -1.3372625 ,-1.2888170, -1.1556655, -0.9695751 ,-0.7253764, -0.4115058)


x_min = min(c(min(PR1),min(PC1)))
x_max = max(c(max(PR1),max(PC1)))
y_min = min(c(min(PR2),min(PC2)))
y_max = max(c(max(PR2),max(PC2)))

plot(PC1,PC2,col = 4, xlim = c(x_min,x_max),ylim = c(y_min,y_max),pch=17,xlab = 'Dimension1',ylab = 'Dimension2',main = 'Correspondence analysis',asp=1)
lines(PR1,PR2,col = 2,type = 'p',pch=16)
text(PC1,PC2,pos=2,cex=0.8,col=3)
text(PR1,PR2,pos=4,cex=0.8,col=1)
abline(h = 0, v = 0, lty=2)
legend("topright", legend = c("column score","row score"),pch=c(17,16),col=c(4,2),pt.cex = 1,cex = 0.5)
Linda-Zhou/PCA documentation built on May 14, 2019, 7:41 a.m.