Is it possible to edit the axes labels for a mosaic plot from the vcd package?
Asked Answered
K

3

5
data("HairEyeColor")
mosaic(HairEyeColor, shade = TRUE)

Resulting plot

Are there arguments I can use to change the labels on the margins of the resulting plot above? For instance, I'd like to change "Male" to "M", "Female" to "F", to avoid text encroachment, and make some notes in the title labels.

I can't find anything about editing axis labels in the package's help page.

Kramer answered 15/9, 2016 at 20:14 Comment(0)
S
5
lnames <- list(Sex = c("M", "F"))
mosaic(HairEyeColor, set_labels=lnames, shade=T)

Or...

mosaic(HairEyeColor, set_labels=list(Sex = c("M", "F")), shade=T)

enter image description here

Sorensen answered 15/9, 2016 at 21:4 Comment(0)
D
4

The vcd package has an intricate system for adjusting labels -- see Labeling in the Strucplot Framework.

Labels can be abbreviated with abbreviate_labs. The vector order matches the order of the splits: Hair, Eye, Sex.

vcd::mosaic(HairEyeColor, shade = TRUE, labeling_args = list(abbreviate_labs = c(5, 5, 1)))

mosaic plot

Depraved answered 12/10, 2019 at 22:45 Comment(0)
P
2

I'd add that you can augment the space between labels in case there are too many labels, changing this parameter:

spacing = vcd::spacing_conditional(sp = unit(0.3, "lines"), start = unit(2, "lines"), rate = 1.8)

Specifically, you must change sp = unit(0.3, "lines") instead of 0.3 which is the default value.

Platt answered 20/12, 2019 at 22:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.