R vcd::mosaic 重叠标签 [英] R vcd::mosaic overlapping labels

查看:60
本文介绍了R vcd::mosaic 重叠标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 vcd::mosaic 生成马赛克图.但是我得到的因素的文本很长(删掉它们不是一种选择,而且在这么多情况下,引入 \n 似乎令人生畏),所以文本中有重叠,我无法强制标签垂直于轴.

I'm generating a mosaic plot with vcd::mosaic. But the text of the factors I was given are very long (cutting them is not an option, and with so many instances, introducing \n seems daunting), so there's an overlap in the texts, and I haven't been able to force the labels to go perpendicular to the axis.

这就是我正在尝试的:

a <- data.frame(x=sample(LETTERS[1:4],16,replace = TRUE), 
                y=rep(paste("very long label here at number", 1:4, paste=" "), 4))
mosaic(y ~ x, data= a, las= 2)

但这就是我得到的:

我也试过 par(las= 2)par(las= 3) 但这些都不能强制它们垂直对齐(las= 2 与 mosaicplot 配合得很好.就像 vcd::mosaic 覆盖 las 作为给定参数或作为 par 中的默认设置.我也玩过 par(mar),但标签的长度足以欺骗该解决方法.

I've also tryed par(las= 2) and par(las= 3) but none of those is able to force them into vertical alignment (las= 2 works well with mosaicplot, though. It's like vcd::mosaic overrides las either as a given parameter or as a default-set in par. I've played also with par(mar), but the labels are long enough to fool that workaround.

我该怎么做才能获得可读的标签?

What can I do to get readable labels?

########## 编辑添加:##########

我也试过了,没用:

mosaic(y ~ x, data= a, labeling_list= list(gp_text= gpar(las= 2)))

mosaic(y ~ x, data= a, labeling_list= list(rot_labels = c(0,90,0,0)))
  # Actually placed the "90" in the 4 positions

mosaic(y ~ x, data= a, labeling_list= list(rot_varnames = c(0,90,0,0)))

推荐答案

终于找到了!关键搜索文档:

Finally found it! Key searching docs:

?labelings
?labeling_border

为了旋转标签

mosaic(y ~ x, 
       data= a, 
       labeling= labeling_border(rot_labels = c(90,0,0,0), 
                                 just_labels = c("left", 
                                                 "center", 
                                                 "center", 
                                                 "center")))

这篇关于R vcd::mosaic 重叠标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆