0

I have this contingency table:

> ftable(mytable) # print table
                Sex     female male
Pclass Survived                    
1      No             0      5  118
       Si             0    139   61
2      No             0     12  146
       Si             0     94   25
3      No             0    110  418
       Si             0    106   75

Then, I make a mosaic plot using the base package of R. The code and the graphic are the following:

mosaicplot(mytable, color=c("#fb8072", "#8dd3c7"), cex.axis=1.2)

enter image description here

Now I want to dissapear the names female and male from the x-axis and put that names as a legend so that it's specified that pink refert to female and light blue to male. How Can I do that?

EDIT 1:

The output of "mytable" is :

mytable <- structure(c(0, 5, 118, 0, 139, 61, 0, 12, 146, 0, 94, 25, 0, 
110, 418, 0, 106, 75), .Dim = c(3L, 2L, 3L), .Dimnames = structure(list(
    Sex = c("", "female", "male"), Survived = c("No", "Si"), 
    Pclass = c("1", "2", "3")), .Names = c("Sex", "Survived", 
"Pclass")), class = c("xtabs", "table"))

EDIT 2:

Before the code to plot the mosaic , I got to remove the names of categories in the plot removing the names from the contingency table with the following code:

dimnames(mytable)[["Sex"]] = rep(NA,3)

Now, the only thing that remains without resolution is to add a legend.

CreamStat
  • 2,155
  • 6
  • 27
  • 43
  • You might be interested by http://stackoverflow.com/a/26051862/3710546 –  Jan 22 '16 at 07:31
  • Perhaps you are interessted in using ggplot2 for your Mosaicplots? There are different solutions in this question using an extra color legend: http://stackoverflow.com/questions/19233365/how-to-create-a-marimekko-mosaic-plot-in-ggplot2 – Patrick Roocks Jan 22 '16 at 07:49

0 Answers0