2 norm.vec <- function(v, min, max) {
8 fac <- (max-min)/(vr[2]-vr[1])
14 #x a table with freq and rank, rownames are words
17 prototypical <- function(x, mfreq = NULL, mrank = NULL, cexrange=c(0.8, 3), cexalpha = c(0.5, 1), labfreq = TRUE, labrank = TRUE, cloud = TRUE, type = 'classical', r.names=NULL, colors=NULL, mat.col.path = NULL) {
20 mfreq <- sum(x[,1]) / nrow(x)
23 mrank <- sum(x[,1] * x[,2]) / sum(x[,1])
27 if (is.null(r.names)) {
28 r.names <- rownames(x)
30 ord.ori <- order(x[,1], decreasing=T)
31 r.names <- r.names[order(x[,1], decreasing=T)]
32 x <- x[order(x[,1], decreasing = TRUE),]
33 x[,2] <- round(x[,2],2)
34 ZN <- which(x[,1] >= mfreq & x[,2] <= mrank)
35 FP <- which(x[,1] >= mfreq & x[,2] > mrank)
36 SP <- which(x[,1] < mfreq & x[,2] > mrank)
37 CE <- which(x[,1] < mfreq & x[,2] <= mrank)
38 mfreq <- round(mfreq, 2)
39 mrank <- round(mrank, 2)
40 toplot <- list(ZN, FP, SP, CE)
41 labcex <- norm.vec(x[,1], cexrange[1], cexrange[2])
42 labalpha <- norm.vec(x[,2], cexalpha[2], cexalpha[1])
43 labalpha <- rgb(0.1,0.2,0.1, labalpha)
44 if (is.null(colors)) {
45 labcol <- rep('orange', nrow(x))
48 labcol[ZN] <- 'lightblue'
50 labcol <- colors[ord.ori]
52 mat.col <- cbind(r.names, labcol)
53 #write.table(mat.col,file=mat.col.path)
54 ti <- c("Zone du noyau", "Première périphérie", "Seconde périphérie", "Elements contrastés")
55 if (type == 'classical') {
57 layout(matrix(c(1,4,2,3), nrow=2))
58 for (i in 1:length(toplot)) {
59 rtoplot <- toplot[[i]]
60 if (length(rtoplot)) {
63 labels <- paste(r.names[rtoplot], x[rtoplot,1], x[rtoplot,2], sep='-')
64 wordcloud(labels, x[rtoplot,1], scale = c(max(labcex[rtoplot]), min(labcex[rtoplot])), color = labalpha[rtoplot], random.order=FALSE, rot.per = 0)
68 plot(0,0,pch='', axes = FALSE)
70 for (val in rtoplot) {
71 yval <- yval-(strheight(r.names[val],cex=labcex[val])+0.02)
72 text(-0.9, yval, paste(r.names[val], x[val,1], x[val,2], sep = '-'), cex = labcex[val], col = labalpha[val], adj=0)
79 mtext(paste('<', mfreq, ' Fréquences ', '>=', mfreq, sep = ' '), side=2, line=1, cex=1, col="red", outer=TRUE)
80 mtext(paste('<=', mrank, ' Rangs ', '>', mrank, sep = ' '), side=3, line=1, cex=1, col="red", outer=TRUE)
81 } else if (type == 'plan') {
83 textplot(x[,1], x[,2], r.names, cex=labcex, xlim=c(min(x[,1])-nrow(x)/3, max(x[,1])+5), ylim = c(min(x[,2])-0.2, max(x[,2])+0.5), col=labcol, xlab="", ylab="")
86 legend('topright', ti, fill=c('lightblue', 'red', 'green', 'orange'))
87 mtext(paste('<', mfreq, ' Fréquences ', '>=', mfreq, sep = ' '), side=1, line=1, cex=1, col="red", outer=TRUE)
88 mtext(paste('<=', mrank, ' Rangs ', '>', mrank, sep = ' '), side=2, line=1, cex=1, col="red", outer=TRUE)
93 proto3D <- function(x, mfreq = NULL, mrank = NULL, cexrange=c(0.8, 3), cexalpha = c(0.5, 1), labfreq = TRUE, labrank = TRUE, cloud = TRUE, type = 'classical', r.names=NULL, colors=NULL) {
96 mfreq <- sum(x[,1]) / nrow(x)
99 mrank <- sum(x[,1] * x[,2]) / sum(x[,1])
103 if (is.null(r.names)) {
104 r.names <- rownames(x)
106 ord.ori <- order(x[,1], decreasing=T)
107 r.names <- r.names[order(x[,1], decreasing=T)]
108 x <- x[order(x[,1], decreasing = TRUE),]
109 x[,2] <- round(x[,2],1)
110 ZN <- which(x[,1] >= mfreq & x[,2] <= mrank)
111 FP <- which(x[,1] >= mfreq & x[,2] > mrank)
112 SP <- which(x[,1] < mfreq & x[,2] > mrank)
113 CE <- which(x[,1] < mfreq & x[,2] <= mrank)
114 mfreq <- round(mfreq, 2)
115 mrank <- round(mrank, 2)
116 toplot <- list(ZN, FP, SP, CE)
117 labcex <- norm.vec(x[,1], cexrange[1], cexrange[2])
118 labalpha <- norm.vec(x[,2], cexalpha[2], cexalpha[1])
119 labalpha <- rgb(0.1,0.2,0.1, labalpha)
120 if (is.null(colors)) {
121 labcol <- rep('black', nrow(x))
123 labcol[SP] <- 'green'
126 labcol <- colors[ord.ori]
128 ti <- c("Zone du noyau", "Première périphérie", "Seconde périphérie", "Elements contrastés")
129 if (type == 'classical') {
131 layout(matrix(c(1,4,2,3), nrow=2))
132 for (i in 1:length(toplot)) {
133 rtoplot <- toplot[[i]]
134 if (length(rtoplot)) {
137 labels <- paste(r.names[rtoplot], x[rtoplot,1], x[rtoplot,2], sep='-')
138 wordcloud(labels, x[rtoplot,1], scale = c(max(labcex[rtoplot]), min(labcex[rtoplot])), color = labalpha[rtoplot], random.order=FALSE, rot.per = 0)
142 plot(0,0,pch='', axes = FALSE)
144 for (val in rtoplot) {
145 yval <- yval-(strheight(r.names[val],cex=labcex[val])+0.02)
146 text(-0.9, yval, paste(r.names[val], x[val,1], x[val,2], sep = '-'), cex = labcex[val], col = labalpha[val], adj=0)
153 mtext(paste('<', mfreq, ' Fréquences ', '>=', mfreq, sep = ' '), side=2, line=1, cex=1, col="red", outer=TRUE)
154 mtext(paste('<=', mrank, ' Rangs ', '>', mrank, sep = ' '), side=3, line=1, cex=1, col="red", outer=TRUE)
155 } else if (type == 'plan') {
158 rgl.lines(c(range(x[,1])), c(mrank, mrank), c(0, 0), col = "#000000")
159 rgl.lines(c(mfreq,mfreq),c(range(x[,2])),c(0,0),col = "#000000")
160 rgl.lines(c(mfreq,mfreq),c(mrank,mrank),c(-1,1),col = "#000000")
162 #textplot(x[,1], x[,2], r.names, cex=labcex, xlim=c(min(x[,1])-nrow(x)/3, max(x[,1])+5), ylim = c(min(x[,2])-0.2, max(x[,2])+0.5), col=labcol, xlab="", ylab="")
165 legend('topright', ti, fill=c('blue', 'red', 'green', 'black'))
166 mtext(paste('<', mfreq, ' Fréquences ', '>=', mfreq, sep = ' '), side=1, line=1, cex=1, col="red", outer=TRUE)
167 mtext(paste('<=', mrank, ' Rangs ', '>', mrank, sep = ' '), side=2, line=1, cex=1, col="red", outer=TRUE)
171 intervalle.freq <- function(x, SX=NULL) {
172 errorn <- (x/SX) + (1.96 * sqrt(((x/SX) * (1-(x/SX))/SX)))