font size...
[iramuteq] / Rscripts / plotafcm.R
1 #library(ca)
2 #datadm<-read.table('/home/pierre/.hippasos/corpus_agir.csv',header=TRUE,sep='\t',quote='\"')
3 #data.mjca<-mjca(datadm[,-1],supcol=c(1:12),nd=6)
4
5 tridata<-function(tabletot,nb=10,fnb=2) {
6     #atrier = x
7     #sumx<-summary(atrier)
8     #tabletot<-as.data.frame(sumx[3])
9     tabletotf1<-tabletot[order(tabletot[,5]),]
10     rowkeep1<-tabletotf1[1:nb,]
11     rowkeep1<-rbind(rowkeep1,tabletotf1[(nrow(tabletotf1)-nb):nrow(tabletotf1),])
12     rowf1names<-rownames(rowkeep1)
13     tabletotf2<-tabletot[order(tabletot[,8]),]
14     rowkeep2<-tabletotf2[1:nb,]
15     rowkeep2<-rbind(rowkeep2,tabletotf2[(nrow(tabletotf2)-nb):nrow(tabletotf2),])
16     rowf2names<-rownames(rowkeep2)
17     count<-0
18     for (names in 1:length(rowf1names)) {
19         for (names2 in 1:length(rowf2names)) {  
20             if (rowf1names[names]==rowf2names[names2]) {
21                 rowkeep1<-rowkeep1[-(as.numeric(names)-count),]
22                 count<-count+1
23                 }
24             }
25     }
26     rowkeep12<-rbind(rowkeep1,rowkeep2)
27     if (fnb>=3) {
28         count<-0
29         row12names<-rownames(rowkeep12)
30         tabletotf3<-tabletot[order(tabletot[,14]),]
31         rowkeep3<-tabletotf1[1:nb,]
32         rowkeep3<-rbind(rowkeep3,tabletotf3[(nrow(tabletotf3)-nb):nrow(tabletotf3),])
33         rowf3names<-rownames(rowkeep3)
34         for (names in 1:length(row12names)) {
35             for (names3 in 1:length(rowf3names)) {
36                 if (rowf3names[names3]==row12names[names]) {
37                     rowkeep12<-rowkeep12[-(as.numeric(names)-count),]
38                     count<-count+1
39                 }
40             }
41         }
42         rowkeep123<-rbind(rowkeep12,rowkeep3)
43         rowkeep123
44     }
45     else {
46         rowkeep12 }
47 }
48 #rowkeep<-tridata(data.mjca,nb=50,fnb=3)
49 #matrow<-as.matrix(rowkeep)
50 #x<-as.numeric(matrow[,5])
51 #y<-as.numeric(matrow[,8])
52 #z<-as.numeric(matrow[,11])
53 #labels<-matrow[,1]
54 #plot3d(x,y,z,xlab='',ylab='',zlab='',box=FALSE,axes=FALSE)
55 #text3d(x,y,z,labels)
56 #rgl.bg(col = c("#aaaaaa", "#99bb99"), front = "lines", box=FALSE, sphere = TRUE)
57 #rgl.lines(c(range(x)), c(0, 0), c(0, 0), col = "#0000ff")
58 #rgl.lines(c(0,0),c(range(y)),c(0,0),col = "#0000ff")
59 #rgl.lines(c(0,0),c(0,0),c(range(z)),col = "#0000ff")
60 #text3d(range(x)[2]+1,0,0,'f1')
61 #text3d(0,range(y)[2]+1,0,'f2')
62 #text3d(0,0,range(z)[2]+1,'f3')
63 #plot(as.numeric(matrow[,5]),as.numeric(matrow[,8]))
64 #text(as.numeric(matrow[,5]),as.numeric(matrow[,8]),matrow[,1])
65
66 tridata2<-function(tabletot,nb=5,fnb=2) {
67         #atrier = x
68         #sumx<-summary(atrier)
69         #tabletot<-as.data.frame(sumx[3])
70         tabletotf1<-tabletot[order(tabletot[,1]),]
71         rowkeep1<-tabletotf1[1:nb,]
72         rowkeep1<-rbind(rowkeep1,tabletotf1[(nrow(tabletotf1)-nb):nrow(tabletotf1),])
73         rowf1names<-rownames(rowkeep1)
74         tabletotf2<-tabletot[order(tabletot[,2]),]
75         rowkeep2<-tabletotf2[1:nb,]
76         rowkeep2<-rbind(rowkeep2,tabletotf2[(nrow(tabletotf2)-nb):nrow(tabletotf2),])
77         rowf2names<-rownames(rowkeep2)
78         count<-0
79         for (names in 1:length(rowf1names)) {
80                 for (names2 in 1:length(rowf2names)) {  
81                         if (rowf1names[names]==rowf2names[names2]) {
82                                 rowkeep1<-rowkeep1[-(as.numeric(names)-count),]
83                                 count<-count+1
84                         }
85                 }
86         }
87         rowkeep12<-rbind(rowkeep1,rowkeep2)
88         if (fnb>=3) {
89                 count<-0
90                 row12names<-rownames(rowkeep12)
91                 tabletotf3<-tabletot[order(tabletot[,3]),]
92                 rowkeep3<-tabletotf1[1:nb,]
93                 rowkeep3<-rbind(rowkeep3,tabletotf3[(nrow(tabletotf3)-nb):nrow(tabletotf3),])
94                 rowf3names<-rownames(rowkeep3)
95                 for (names in 1:length(row12names)) {
96                         for (names3 in 1:length(rowf3names)) {
97                                 if (rowf3names[names3]==row12names[names]) {
98                                         rowkeep12<-rowkeep12[-(as.numeric(names)-count),]
99                                         count<-count+1
100                                 }
101                         }
102                 }
103                 rowkeep123<-rbind(rowkeep12,rowkeep3)
104                 rowkeep123
105         }
106         else {
107                 rowkeep12 }
108 }
109
110 uncover<-function(tabletot,x) {
111         #tabletot=tableau des coordonnées
112         tabletotf1<-tabletot$table[order(tabletot$table[,x]),]
113         ref<-tabletotf1[1,]
114         distminx<-0.4
115         distminy<-0.2
116         i<-2
117         #k=nrow(elim)
118         if (is.null(tabletot$elim)){
119                 elim<-NULL#tabletot#$elim
120         } else {
121                 elim=tabletot$elim
122         }
123         while (i < nrow(tabletotf1)) {
124                 signex<-ref[1]*tabletotf1[i,1]
125                 signey<-ref[2]*tabletotf1[i,2]
126                 if (signex>0) {
127                         dist<-abs(ref)-abs(tabletotf1[i,])
128                         dist<-abs(dist)
129                         print(dist)
130                         if (abs(dist[1])<distminx) {
131                                 if (signey>0){
132                                         if (abs(dist[2])<distminy) {
133                                                 elim<-rbind(elim,tabletotf1[i,])
134                                                 row.names(elim)[nrow(elim)]<-row.names(tabletotf1)[i]
135                                                 #k<-k+1
136                                                 tabletotf1<-tabletotf1[-i,]
137                                         }else{
138                                                 ref<-tabletotf1[i,]
139                                                 i<-i+1
140                                         }
141                                 }else{ref<-tabletotf1[i,];i<-i+1}
142                                 
143                         }else{
144                                 ref<-tabletotf1[i,]
145                         #       print(ref)
146                                 i<-i+1
147                         }
148                 }else {
149                         ref<-tabletotf1[i,]
150                         i<-i+1
151                 }
152         } 
153         print(length(tabletotf1))
154         elim<-elim[-1,]
155         out<-list()
156         out$table<-tabletotf1
157         out$elim<-elim
158         out
159         
160 }
161 #ntb<-tabletot[order(tabletot[,1]),]
162 #ntb2<-uncover(ntb)
163 #ntb2$table<-ntb2$table[order(ntb2$table[,2]),]
164 #ntb2$table<-uncover(ntb2$table)
165
166
167
168 #               if (tabletotf1[i,1])
169 #               ref<-
170 #       }
171 #       rowkeep1<-tabletotf1[1:nb,]
172 #       rowkeep1<-rbind(rowkeep1,tabletotf1[(nrow(tabletotf1)-nb):nrow(tabletotf1),])
173 #       rowf1names<-rownames(rowkeep1)
174 #       tabletotf2<-tabletot[order(tabletot[,2]),]
175 #       rowkeep2<-tabletotf2[1:nb,]
176 #       rowkeep2<-rbind(rowkeep2,tabletotf2[(nrow(tabletotf2)-nb):nrow(tabletotf2),])
177 #       rowf2names<-rownames(rowkeep2)
178 #       count<-0
179 #       for (names in 1:length(rowf1names)) {
180 #               for (names2 in 1:length(rowf2names)) {  
181 #                       if (rowf1names[names]==rowf2names[names2]) {
182 #                               rowkeep1<-rowkeep1[-(as.numeric(names)-count),]
183 #                               count<-count+1
184 #                       }
185 #               }
186 #       }
187 #       rowkeep12<-rbind(rowkeep1,rowkeep2)
188 #       if (fnb>=3) {
189 #               count<-0
190 #               row12names<-rownames(rowkeep12)
191 #               tabletotf3<-tabletot[order(tabletot[,3]),]
192 #               rowkeep3<-tabletotf1[1:nb,]
193 #               rowkeep3<-rbind(rowkeep3,tabletotf3[(nrow(tabletotf3)-nb):nrow(tabletotf3),])
194 #               rowf3names<-rownames(rowkeep3)
195 #               for (names in 1:length(row12names)) {
196 #                       for (names3 in 1:length(rowf3names)) {
197 #                               if (rowf3names[names3]==row12names[names]) {
198 #                                       rowkeep12<-rowkeep12[-(as.numeric(names)-count),]
199 #                                       count<-count+1
200 #                               }
201 #                       }
202 #               }
203 #               rowkeep123<-rbind(rowkeep12,rowkeep3)
204 #               rowkeep123
205 #       }
206 #       else {
207 #               rowkeep12 }
208 #}