Question

I'm trying to make a mosaic plot with the vcd package, and i'm having an hard time understanding how to configure some settings of the plot.

library(vcd)
library(RColorBrewer)
mydf <- structure(list(A=structure(c(7L,6L,7L,6L,7L,1L,5L,4L,7L,6L,6L,6L,6L,6L,
                                     3L,6L,6L,6L,5L,3L),
                           .Label=c("a","b","c","d","e","f","g","h","i"),
                           class="factor"),
               B=structure(c(3L,2L,1L,1L,3L,3L,3L,3L,2L,3L,3L,1L,3L,
                                3L,3L,3L,3L,3L,3L,3L),
                           .Label=c("a","b","c"),
                           class="factor")),
          .Names=c("A","B"),
          row.names=c(1L,  2L,  3L,  4L,  5L,  6L,  7L,  8L,  9L, 
                      10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L),
          class="data.frame")

mosaic( ~ A + B, data=mydf, highlighting="A", 
        highlighting_fill=brewer.pal(9, "Set3"))

The legend of the different levels of the A variable are on the top of the plot, which is not ver helpful since the category "a", of variable B does not have all those levels. I would like the legend to be in the bottom to be together with the category that has all the levels in the legend.

Was it helpful?

Solution

From ?labeling I learned there were several "behind the scenes" functions that accept arguments from mosaic and tried a couple of changes:

?labeling

I believe this is closer to what you were hoping for:

 mosaic( ~ A + B, data=mydf, highlighting="A", 
      highlighting_fill=brewer.pal(9, "Set3"),
      labeling_args=list(tl_labels =c(TRUE, FALSE) ) )

Sets the row labels to the bottom and uses the lower cell locations for placement. (Still have overlap of 'h' and 'i' but they can even be resoved, whereas you had overlap of a-e before.)

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top