Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name the "superscriptions" of dimensions in r?

Tags:

r

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.

like image 948
v_e Avatar asked Dec 04 '25 18:12

v_e


1 Answers

You can specify dimnames this way :

dimnames(test) <- list(foo=colnames(test),bar=rownames(test))
mosaic(test, shade=T, legend=T)

enter image description here

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)

enter image description here

like image 95
juba Avatar answered Dec 06 '25 07:12

juba