afc
[iramuteq] / Rscripts / Rgraph.R
index ffbee4c..b0b555c 100644 (file)
@@ -43,7 +43,7 @@ PlotDendroCut <- function(chd,filename,reso,clusternb) {
 #      dev.off()
 #}
 
-PlotAfc2dCoul<- function(afc,chisqrtable,filename, what='coord',col=FALSE, axetoplot=c(1,2), deb=0,fin=0, width=900, height=900, quality=100, reso=200, parcex=PARCEX, xlab = NULL, ylab = NULL, xmin=NULL, xmax=NULL, ymin=NULL, ymax=NUL) {
+PlotAfc2dCoul<- function(afc,chisqrtable,filename, what='coord',col=FALSE, axetoplot=c(1,2), deb=0,fin=0, width=900, height=900, quality=100, reso=200, parcex=PARCEX, xlab = NULL, ylab = NULL, xmin=NULL, xmax=NULL, ymin=NULL, ymax=NULL) {
        if (col) {
                if (what == 'coord') {
                        rowcoord <- as.matrix(afc$colcoord)
@@ -94,11 +94,10 @@ PlotAfc2dCoul<- function(afc,chisqrtable,filename, what='coord',col=FALSE, axeto
 
        open_file_graph(filename, width = width, height = height)
        par(cex=PARCEX)
-
     table.in <- rowcoord[order(cex.par, decreasing = TRUE),]
     classes <- classes[order(cex.par, decreasing = TRUE)]
     cex.par <- cex.par[order(cex.par, decreasing = TRUE)]
-    table.in <- stopoverlap(table.in, cex.par=cex.par)
+    table.in <- stopoverlap(table.in, cex.par=cex.par, xlim = c(xmin,xmax), ylim = c(ymin,ymax))
     classes <- classes[table.in[,4]]
     cex.par <- cex.par[table.in[,4]]
     make_afc_graph(table.in, classes, clnb, xlab, ylab, cex.txt = cex.par, xminmax=c(xmin,xmax), yminmax=c(ymin,ymax))
@@ -173,7 +172,7 @@ overlap <- function(x1, y1, sw1, sh1, boxes) {
     .Call("is_overlap",x11,y11,sw11,sh11,boxes1)
 }
 ########################################################
-stopoverlap <- function(x, cex.par = NULL) {
+stopoverlap <- function(x, cex.par = NULL, xlim = NULL, ylim = NULL) {
 #from wordcloud
     library(wordcloud)
     tails <- "g|j|p|q|y"
@@ -184,7 +183,7 @@ stopoverlap <- function(x, cex.par = NULL) {
     toplot <- NULL
 
 #    plot.new()
-    plot(x[,1],x[,2], pch='')
+    plot(x[,1],x[,2], pch='', xlim = xlim, ylim = ylim)
 
     words <- rownames(x)
     if  (is.null(cex.par))  {
@@ -202,8 +201,6 @@ stopoverlap <- function(x, cex.par = NULL) {
                y1<- x[i,2]
                wid <- strwidth(words[i],cex=size[i])
                ht <- strheight(words[i],cex=size[i])
-           ht <- (ht + ht*.2) + .01
-        wid <- (wid + wid*.1) + .01
                isOverlaped <- TRUE
                while(isOverlaped){
                        if(!overlap(x1-.5*wid,y1-.5*ht,wid,ht, boxes)) { #&&
@@ -265,12 +262,12 @@ make_dendro_cut_tuple <- function(dendro_in, coordok, classeuce, x, nbt = 9) {
        dendro <- gsub('a','',dendro)
        dendro_tot_cl <- read.tree(text = dendro)
        #FIXME
-       for (i in 1:10) {
+       for (i in 1:100) {
                for (cl in 1:clnb) {
                        dendro <- gsub(paste('\\(',cl,',',cl,'\\)',sep=''),cl,dendro)
                }
        }
-       for (i in 1:10) {
+       for (i in 1:100) {
                dendro <- gsub(paste('\\(',0,',',0,'\\)',sep=''),0,dendro)
                for (cl in 1:clnb) {
                        dendro <- gsub(paste('\\(',0,',',cl,'\\)',sep=''),cl,dendro)
@@ -428,13 +425,8 @@ create_afc_table <- function(x) {
 }
 
 make_afc_graph <- function(toplot, classes, clnb, xlab, ylab, cex.txt = NULL, leg = FALSE, cmd = FALSE, black = FALSE, xminmax=NULL, yminmax=NULL) {
-    if (is.null(xminmax)) {
-        xminmax <- c(min(toplot[,1]) + (0.1 * min(toplot[,1])), max(toplot[,1]) + (0.1 * max(toplot[,1])))
-    }
-    if (is.null(yminmax)) {
-        yminmax <- c(min(toplot[,2]) + (0.1 * min(toplot[,2])), max(toplot[,2]) + (0.1 * max(toplot[,2])))
-    }
-       rain <- rainbow(clnb)
+    
+    rain <- rainbow(clnb)
     compt <- 1
     tochange <- NULL
     for (my.color in rain) {