With a large number of variables, the sizing of tick mark labels is too large in barplots along the diagonal of a mosaic pairs plot created with pairs_barplot() in the R vcd package. Is there any way to make them smaller? Here is a minimal working example:
library(vcd)
#> Loading required package: grid
library(vcdExtra)
#> Loading required package: gnm
pairs(table(ICU[,c(1,3:9)]),
diag_panel = pairs_barplot(
gp_vartext = gpar(fontsize = 10, fontface = 2),
gp_leveltext = gpar(fontsize = 8),
abbreviate = 1,
var_offset = 1.25))

Created on 2021-10-16 by the reprex package (v2.0.1)
Currently, you cannot set
gpar()for drawing the y-axis of the bar plot explicitly. There are two general workarounds, though: (1) Not messing with the font sizes but instead plotting on a bigger device. (2) Setting an outer viewport with a differentgpar(fontsize = ...)that is used as the viewports further down in the plot.(1) Bigger device
For illustration I use a
png()device here because the PNG graphic is what I embed on StackOverflow. But, of course, you could use the same trick on other devices including those that you do not create yourself but via chunk options in R/Markdown etc.I use a device size of 13 x 13 inches (as opposed to a more common setting of 6 x 6 or 7 x 7 inches). Then I can omit all of the
gpar()settings because the device is large enough to accomodate the default parameters. I still setabbreviateandvar_offset, though.(2) Outer viewport
Alternatively, I can create a new
gridpage myself and push a viewport withgpar(fontsize = 7)used as the default in this viewport and its children. Then I keep yourgpar()settings inpairs_barplot()and just addnewpage = FALSEin thepairs()call because I want to use the page I already created.Then all font sizes are decreased so that plotting on a 7 x 7 inches device works fine.