perhaps a dumb question, yet I cannot find an answer. If I make a mosaic plot with a vcd package so:
library(vcd)
test<-matrix(c(65,31,495,651), ncol=2,byrow=T)
colnames(test)<-c("2010", "2011")
rownames(test)<-c("yes", "now")
mosaic(test, shade=T, legend=T)
it works like a charm except that the superscriptions over the years and the outputs (yes/no) are shown "A" and "B".
I would like to name these "Years" and "Outputs" but I cannot find a parameter for this. How could I do this? Thanks in advance.
You can specify dimnames this way :
dimnames(test) <- list(foo=colnames(test),bar=rownames(test))
mosaic(test, shade=T, legend=T)

In fact, mosaic is better suited to be applied to contingency tables, where the labels are determined by the table function :
color <- sample(c("red","blue"),10,replace=TRUE)
color2 <- sample(c("yellow","green"),10,replace=TRUE)
tab <- table(color,color2)
mosaic(tab, shade=T)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With