[英]R vcd::mosaic overlapping labels
I'm generating a mosaic plot with vcd::mosaic
. 我正在用
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. 但是给我的因素的文本很长(切掉它们不是一种选择,并且在很多情况下,引入
\\n
似乎令人生畏),因此文本中存在重叠之处,我无法强制执行标签垂直于轴。
This is what I'm trying: 这是我正在尝试的:
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)
but this is what I get: 但这就是我得到的:
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. 我也尝试过
par(las= 2)
和par(las= 3)
但是没有一个能够强迫它们垂直对齐( las= 2
可以很好地与mosaicplot
配合使用。就像vcd::mosaic
覆盖了las
作为给定参数或作为par
的默认设置,我也使用过par(mar)
,但是标签足够长,足以使该解决方法无效。
What can I do to get readable labels? 我该怎么做才能获得可读的标签?
########## EDIT TO ADD: ########## ##########编辑添加:##########
I've also tried this, to no avail: 我也尝试过这个,但无济于事:
mosaic(y ~ x, data= a, labeling_list= list(gp_text= gpar(las= 2)))
and 和
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
In order to rotate the labels 为了旋转标签
mosaic(y ~ x,
data= a,
labeling= labeling_border(rot_labels = c(90,0,0,0),
just_labels = c("left",
"center",
"center",
"center")))
Try this: 尝试这个:
+ theme(axis.text.x=element_text(angle=-25, hjust= .1))
it will rotate labels for 25 degrees (you can just copy and paste) 它将标签旋转25度(您可以复制和粘贴)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.