[R] adding a caption to a mosaic plot?

Simon Kiss sjkiss at gmail.com
Wed May 2 20:11:30 CEST 2012


Dear all:
Is there a way to add text to the margins or outer margins of a mosaic plot using the vcd package? I understand the margins argument to mosaic, but I don't know how to add text to that. 
I'd like to add a caption to a plot.  If possible, I'd like to know how to set the font and size for that function as well. My plot looks roughly as below. 
Thank you for your time!
Simon J. Kiss

mydat<-data.frame(gender=factor(rbinom(100, 1, 0.5),  labels=c('female', 'male')), hair=factor(rbinom(100, 1, 0.5), labels=c('blonde', 'black')))
mosaic_1<-table(mydat)             
mosaic(mosaic_1, gp=shading_hsv, main='my title', pop=FALSE, split_vertical=FALSE,  margins=c(4.1, 2.1, 8, 5.1), labeling_args=list(rot_labels=c(left=0), offset_labels=c(left=3), gp_main=gpar(cex=2), offset_varnames=c(left=5.5), gp_labels=gpar(cex=1.5), gp_varnames=gpar(cex=1.5), labeling_values=c('observed')))
labeling_cells(text=round(prop.table(mosaic_1, 1)*100), gp_text=gpar(ces=2), clip=FALSE)(mosaic_1)

*********************************
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606



More information about the R-help mailing list