简体   繁体   English

是否可以从 vcd 包中编辑马赛克图的轴标签?

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

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.比如我想把“男”改成“M”,“女”改成“F”,避免文字侵占,并在标题标签上做一些注释。

I can't find anything about editing axis labels in the package's help page.我在包的帮助页面中找不到任何关于编辑轴标签的信息。

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)

在此处输入图片说明

The vcd package has an intricate system for adjusting labels -- see Labeling in the Strucplot Framework . vcd包有一个用于调整标签的复杂系统——请参阅Strucplot 框架中的标签

Labels can be abbreviated with abbreviate_labs .标签可以缩写为abbreviate_labs The vector order matches the order of the splits: Hair , Eye , Sex .向量顺序与拆分顺序匹配: HairEyeSex

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

马赛克图

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.具体来说,您必须更改sp = unit(0.3, "lines")而不是默认值 0.3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM