...
[iramuteq] / Rscripts / splitafc.R
1 #library(ca)
2 #datadm<-read.csv2(file('TableCont.csv', encoding='utf-8'))
3 #afc<-ca(datadm, nd=3)
4 plotqrtafc<- function(afc,x=1,y=2,supcol=NA,filename='afcdiv4_',width=480,height=480,quality=75,reso=200,ptsize=12,PARCEX=PARCEX) {
5     if (is.na(supcol)) {
6         noc<-afc$colnames
7         colcoord<-afc$colcoord
8     }
9     else {
10         noc<-afc$colnames[supcol[1]:supcol[2]]
11         colcoord<-afc$colcoord[supcol[1]:supcol[2],]
12     }
13     fiqrt<-data.frame()
14     seqrt<-data.frame()
15     foqrt<-data.frame()
16     thqrt<-data.frame()
17     for (i in 1:(nrow(colcoord))) {
18         if (colcoord[,x][i]<0) {
19             if (colcoord[,y][i]<0) {
20                 foqrt[i,1]<-colcoord[i,x]
21                 foqrt[i,2]<-colcoord[i,y]
22                 foqrt[i,3]<-noc[i]
23             }
24             else {
25                 fiqrt[i,1]<-colcoord[i,x]
26                 fiqrt[i,2]<-colcoord[i,y]
27                 fiqrt[i,3]<-noc[i]
28             }
29         }
30         else {
31             if (colcoord[,2][i]<0) {
32                 thqrt[i,1]<-colcoord[i,x]
33                 thqrt[i,2]<-colcoord[i,y]
34                 thqrt[i,3]<-noc[i]
35             }
36             else {
37                 seqrt[i,1]<-colcoord[i,x]
38                 seqrt[i,2]<-colcoord[i,y]
39                 seqrt[i,3]<-noc[i]
40             }
41         }
42     }   
43     list_name<-c('hg','bg','hd','bd')
44     list_table<-list(fiqrt,foqrt,seqrt,thqrt)
45     for (i in 1:4) {
46             if (Sys.info()["sysname"]=='Darwin') {
47                 width<-width/74.97
48                 height<-height/74.97
49                 print(list_name[i])
50                 quartz(file=paste(filename,x,y,list_name[i],'.jpeg',sep=''),type='jpeg',width=width,height=height)#,pointsize=5)
51             } else {
52                 jpeg(paste(filename,x,y,list_name[i],'.jpeg',sep=''),quality=quality,pointsize=ptsize,res=reso,width=width,height=height)
53             }
54             par(cex=PARCEX)
55                 #par(mar=c(0.01,0.01,0.01,0.01))
56             plot(list_table[[i]][,1],list_table[[i]][,2],pch='')
57             text(list_table[[i]][,1],list_table[[i]][,2],list_table[[i]][,3])
58             dev.off()
59         }
60 #    jpeg(paste(filename,x,y,'bg','.jpeg',sep=''),quality=quality,pointsize=ptsize,res=reso,width=width,height=height)
61 #    par(cex=PARCEX)
62 #    plot(foqrt[,1],foqrt[,2],pch='')
63 #    text(foqrt[,1],foqrt[,2],foqrt[,3])
64 #    dev.off()
65 #    jpeg(paste(filename,x,y,'hd','.jpeg',sep=''),quality=quality,pointsize=ptsize,res=reso,width=width,height=height)
66 #    par(cex=PARCEX)
67 #    plot(seqrt[,1],seqrt[,2],pch='')
68 #    text(seqrt[,1],seqrt[,2],seqrt[,3])
69 #    dev.off()
70 #    jpeg(paste(filename,x,y,'bd','.jpeg',sep=''),quality=quality,pointsize=ptsize,res=reso,width=width,height=height)
71 #    par(cex=PARCEX)
72 #    plot(thqrt[,1],thqrt[,2],pch='')
73 #    text(thqrt[,1],thqrt[,2],thqrt[,3])
74 #    dev.off()
75 }
76
77 #plotqrtafc(afc,x=1,y=2,PARCEX=0.7,quality=100,ptsize=12,reso=200,width=1000,height=1000)