我正在开展一个研究项目,我试图向我的老板展示一些可以放入项目中的清晰图表。我制作了这个筛图,但我无法弄清楚 1. 如何旋转 x 轴标签并将它们从图表中拉出,以及 2. 如何向上移动与图表顶部重叠的 y 轴标签出色地。
我尝试旋转标签,但它仍然与图表重叠。
library(vcd)
library(vcdExtra)
All <- matrix(c(924,139,67,42, 115,66,61,22, 40,37,51,45, 33,19,30,57), 4, 4)
dimnames(All) <- list(Drinking2002 =c("Rare","Light","Moderate","Heavy"), Drinking2014 =c("Rare","Light","Moderate","Heavy"))
All <- as.table(All)
sieve(All, shade = TRUE, labeling = labeling_values, gp_text = gpar(fontface = 2), rot_labels = c(top = 45))
谢谢您的帮助!
1)
rot_labels = c(left = #, top = #)
旋转标签
2) `offset_labels = c(#, #, #, #) 调整距轴的距离。
sieve(All, shade = TRUE, labeling = labeling_values,
gp_text = gpar(fontface = 2),
rot_labels = c(top = 45, left = 0),
offset_labels = c(0.6, 0, 0, 1)
)
或者
sieve(All, shade = TRUE, labeling = labeling_values,
gp_text = gpar(fontface = 2),
rot_labels = c(top = 0, left = 0),
offset_labels = c(0.6, 0, 0, 1)
)
根据here提供的答案进行扩展以获取马赛克图。
sieve(All, shade = TRUE,
labeling = labeling_border(rot_labels = c(30,0,0,30),just_labels = c("left","right","right","right")),
gp_text = gpar(fontface = 2),
rot_labels = c(top = 45))
您可以使用
c(30,0,0,30)
更改旋转程度,并使用 c("left","right","right","right")
进行标签对齐。希望这有帮助。
编辑:添加了屏幕截图
输出1:
使用
just_labels = c("left","right","right","right")
输出2:
使用
just_labels = c("left","right","right","left")