[R] (no subject)

Simon Kiss simonjkiss at yahoo.ca
Mon Oct 31 22:54:11 CET 2011


Dear colleagues
I'm using data that looks like .test and .test1 below to draw two mosaic plots with cell labelling (the row percentages from the tables). 
When I take out the pop=FALSE commands in the mosaic commands and comment out the two lines labelling the cells, then the plots are laid out exactly as I'd like: side-by-side.
But I do require the cell labelling and the pop=FALSE arguments. I suspect I need to add in a call to pushViewport or an upViewport command, but I'm not sure. Any advice is welcome.


library(vcd)
library(grid)


.test<-as.table(matrix(c(1, 2, 3, 4, 5, 6), nrow=3, ncol=2, byrow=TRUE))
              .test<-prop.table(.test, 1)
.test1<-as.table(matrix(c(1, 2, 3, 4), nrow=2, ncol=2, byrow=TRUE))
              .test1<-prop.table(.test1, 1)

dimnames(.test)<-list("Fluoride Cluster"=c('Beneficial\nand Safe', 'Mixed Opinion', 'Harmful With No Benefits'), "Governments Should Not Impose Treatment"=c('Agree', 'Disagree'))
dimnames(.test1)<-list("Vaccines Are Too Much To Handle"= c('Agree' , 'Disagree'), "Governments Should Not Oblige Treatment" =c('Agree', 'Disagree'))
grid.newpage()
                            pushViewport(viewport(layout=grid.layout(1,2)))
pushViewport(viewport(layout.pos.col=1))
                            mosaic(.test, gp=shading_hsv, pop=FALSE, split_verticaL=FALSE, newpage=FALSE, labeling_args=list(offset_varnames=c(top=3), offset_labels=c(top=2)))
labeling_cells(text=round(prop.table(.test, 1), 2)*100, clip=FALSE)(.test)
popViewport()

pushViewport(viewport(layout.pos.col=2))
  mosaic(.test1, gp=shading_hsv, newpage=FALSE,pop=FALSE, split_vertical=FALSE, labeling_args=list(offset_varnames=c(top=3), offset_labels=c(top=2)))
labeling_cells(text=round(prop.table(.test1, 1), 2)*100, clip=FALSE)(.test1)
popViewport(2)
*********************************
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