0

I am looking for a solution on how to raise numbers in the labels of my vcd mosaic plot.

edit: as an example i randomly selected the Sex label in the Titanic dataset:

vnames <- list(set_varnames=c(Sex="Sex=10^X")) 

mosaic(Titanic, labeling_args=vnames)

They always will be displayed as 10^2 and not as 10².

For example working with expression(10^{2}) or

xlab(bquote('Zoospores ('*10^x*') per plastic box'))

in the normal R plots or ggplot2 does not work for the set_varnames= call in labeling_args= in the mosaic()-command of the vcd package.

I could not find an answer to my specific problem in the vcd mosaic plot, only answers regarding labeling in ggplot2 and normal plots..

looking forward to read from you guys !

Alex LP
  • 1
  • 2
  • can you please provide a reproducbile example of your code – Hardik Gupta Oct 23 '17 at 08:58
  • working on the answer, sorry, i am new to the page – Alex LP Oct 23 '17 at 09:16
  • `vnames <- list(set_varnames=c(Sex="Sex=10^X"))` `mosaic(Titanic, labeling_args=vnames)` #### in ggplot `xlab(bquote('Zoospores ('*10^x*') per plastic box'))` worked fine to raise the x so that it is displayed in the exponent, i tried different solutions also with `expression()` they always worked in ggplot or R plots, but not in my mosaic plot labels.. Thats why i think @Jaap is wrong in marking this Question as duplicate (yet i am still a beginner in R, so he might be right after all .. ) – Alex LP Oct 23 '17 at 09:23
  • Do you have an idea what the reason might be that it doesn't work @Hardikgupta ? – Alex LP Oct 25 '17 at 09:21
  • I just checked with David Meyer, the main author of `mosaic()` and maintainer of `vcd`. The problem is that the otherwise very flexible labeling relies on processing character strings, i.e., it pastes `varnames` and inserts them into labels etc. And it is not possible to preserve `expression`s in this workflow. – Achim Zeileis Nov 19 '17 at 19:31
  • Thank you very much for your effort @Achim Zeileis! I will add the labels with gimp or Photoshop now. Since this does not feel very elegant i always try to solve "problems" right at the root. Here however, it seems to be the only way. – Alex LP Nov 24 '17 at 12:59
  • You could try contacting David directly with a concrete (reproducible) example. I think it should be possible to enter the viewport tree after creating the plot and adding annotation at the very end. Essentially you just `seekViewport()` for the right viewport and can then add `grid.text()` with an expression. This is for example what `labeling_cells()` does internally. But David will know best... – Achim Zeileis Nov 24 '17 at 16:43

1 Answers1

0

With the hints of two dedicated members of the statistician community - @Achim Zeileis and David Meyer, i was able to find a rather simple solution.

To stick with the example:

vnames <- list(set_varnames=c(Sex="")) 

mosaic(Titanic, labeling_args=vnames)

grid.text(bquote('Sex ('*10^X*') example'), y=0.9, x=0.46,gp=gpar(fontsize=21))

grid.text() did the job. Since you basically add the label afterwards you have to play a little with x and y to get it in place.

all the best,

Alexander

Alex LP
  • 1
  • 2