[Rd] vcd: mosaicplot() with labels written into cells

Wolfram Fischer - Z/I/M wolfram@fischer-zim.ch
Wed Jan 22 17:49:02 2003


PROPOSAL (a)
    I would like to propose an argument to mosaicplot.default()
    which allows to inscribe the label of the last dimension
	into each cell of the mosaicplot.
	This could make mosaicplots more easily interpretable.


PROPOSAL (b)
	There could be an argument which defines one or more dimensions
	of which the label(s) are token and inscribed into the cells.
	There could be an additional argument for the separator in the
	case of multiple labels.
	[For this proposal I was not yet able to add a code.]
	

CODE FOR PROPOSAL (a)

#==== ADDITIONAL ARGUMENT FOR mosaic.default() =====================

    labels.in.cells = FALSE,  # labels of last dim are written in the cells


#==== NEW FUNCTION IN mosaic.default() =============================

    add.labels.to.cells <- function( x1, x2, y1, y2, i, label ){
        t <- label[[1]][[i]]
        if( 1.1 * strwidth( t, cex=cex ) < x2-x1
        &&  1.1 * strheight( t, cex=cex ) < y2-y1
        )
            text( (x1+x2)/2, (y1+y2)/2 , t, cex=cex )
    }


#==== ADDITIONAL CODE (1) IN FUNCTION mosaic.cell() ================

      if (XP[i] > 0) {
        polygon(c(x.l[i], x.r[i], x.r[i], x.l[i]), 
          c(y1, y1, y2, y2), lty = if (shade) 
            X[i, p + 1]
          else 1, col = if (shade) {
            color[X[i, p + 2]]
          }
          else color[i])
#--- NEW
        if( labels.in.cells )
            add.labels.to.cells( x.l[i], x.r[i], y1, y2, i, label )
#---
      }


#==== ADDITIONAL CODE (2) IN FUNCTION mosaic.cell() ================

      if (YP[j] > 0) {
        polygon(c(x1, x2, x2, x1), c(y.b[j], y.b[j], 
          y.t[j], y.t[j]), lty = if (shade) 
          X[j, p + 1]
        else 1, col = if (shade) {
          color[X[j, p + 2]]
        }
        else color[j])
#--- NEW
        if( labels.in.cells )
            add.labels.to.cells( x1, x2, y.b[j], y.t[j], j, label )
#---
      }

#===================================================================