Phil
Phil

Reputation: 8107

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

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.

Upvotes: 5

Views: 8143

Answers (3)

jtr13
jtr13

Reputation: 1277

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

Upvotes: 4

Frish Vanmol
Frish Vanmol

Reputation: 354

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.

Upvotes: 2

Cyrus Mohammadian
Cyrus Mohammadian

Reputation: 5193

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

Upvotes: 5

Related Questions