问题
data("HairEyeColor")
mosaic(HairEyeColor, shade = TRUE)
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.
回答1:
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)
回答2:
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)))
来源:https://stackoverflow.com/questions/39519608/is-it-possible-to-edit-the-axes-labels-for-a-mosaic-plot-from-the-vcd-package