[R] Justify axis labels in mosaic plot

Jim Lemon jim at bitwrit.com.au
Wed Feb 5 08:32:28 CET 2014


On 02/05/2014 12:41 PM, Derickson, Ryan, VHACIN wrote:
> Hello All,
>
>
>
> I'm trying to right-justify the y-axis labels in a mosaic plot from base
> R. I've tried too many commands (adj specifically) to list here and
> nothing works so far. I'm sure this could be done in the vcd or ggplot2
> packages, but I would prefer to do it with mosaicplot in base R if at
> all possible and I suspect it is possible. Illustration code is below-
> I'm trying to make "q", "qwe", and "qwertyqwerty" right-justified
> instead of left. The prop.table and order bits are unnecessary for the
> sample but I need them for my actual analyses so I included them here in
> case that somehow affects the code needed. I would be incredibly
> appreciative of any help!
>
>
>
> #demo
>
> a<-c("qwertyqwerty", "qwertyqwerty", "qwertyqwerty", "qwe", "qwe",
> "qwe", "q", "q", "q")
>
> b<-c(1, 2, 3, 1, 1, 3, 2, 2, 3)
>
> demo<-data.frame(a, b)
>
> y<-table(demo)
>
> y<-as.table(y[order(rowSums(y)),])
>
> y<-prop.table(y)
>
> plot(y,
>
> dir=c("h", "v"),
>
> las=1)
>
>
Hi Ryan,
The only thing I can offer, and it is an awful kludge, is to overwrite 
the labels on the left:

plot(y,dir=c("h","v"),las=1)>
library(plotrix)
boxed.labels(rep(0.1,3),c(0.83,0.48,0.13),
  c("             q","          qwerty","qwertyqwerty"),
  adj=1,border=NA,cex=0.8,ypad=1.5)

Jim




More information about the R-help mailing list