1

从另一个角度来看,这个问题与这个问题非常相似,但尚未得到回应。
按照建议的代码,我能够生成马赛克图并旋转标签,使它们清晰易读。当(似乎)包中的mosaic()函数vcd无法识别旋转时,问题就出现了,因此它没有调整图形以适应标签,产生如下结果:

马赛克图

有没有办法改变标签和标题之间的边距?如果我是第一个遇到此问题的人,我会感到惊讶。如果适用,我也愿意使用其他软件包来获取马赛克图。

代码

aux = structure(c(0L, 0L, 3L, 46L, 107L, 14L, 0L, 0L, 4L, 0L, 0L, 2L, 
9L, 0L, 23L, 2L, 1L, 3L, 14L, 1L, 8L, 26L, 6L, 11L, 6L, 1L, 6L, 
0L, 1L, 1L, 29L, 10L, 62L, 1L, 3L, 1L, 1L, 3L, 1L), .Dim = c(3L, 
13L), .Dimnames = list(abcdefghi = c("Madrid", "Valencia", "Granada"
), jklmnopqr = c("roknbjftxcwl", "mfchldbxuyig", "gtyoxeduijpw", 
"akbcefymvsiw", "ucbfxplietqk", "mzeykauprfdh", "piermgawyjht", 
"chjvatqbylxo", "merhcogjflbd", "wiyrugvmhjlq", "glszdqmjhkov", 
"giowaxrtsknm", "pxucytzvljqw")), class = "table")

library(vcd)
colours = c("brown","darkgreen","darkgrey","orange","darkred","gold","blue","red",
            "white","pink","purple","navy","lightblue","green","peachpuff","violet","yellow","yellow4")
aux_names = names(attr(aux,"dimnames"))
mosaic(aux,main=paste(aux_names,collapse=" vs. "),
       gp=gpar(fill=matrix(sample(colours,max(nrow(aux),ncol(aux))),1,max(nrow(aux),ncol(aux)))),
       pop = FALSE,labeling = labeling_border(rot_labels=c(90,0,0,0),
                                              just_labels=c("left","right")))
4

1 回答 1

3

这段代码应该做我认为你所追求的。

mosaic(aux,main=paste(aux_names,collapse=" vs. "),
       gp=gpar(fill=matrix(sample(colours,max(nrow(aux),ncol(aux))),1,max(nrow(aux),ncol(aux)))),
       pop = FALSE,labeling = labeling_border(rot_labels=c(90,0,0,0),
                                              just_labels=c("left","right"),
                                              offset_varnames = c(8,8,8,8)),
       margins = c(10, 10, 10, 10))

边距图

于 2019-06-04T11:30:20.153 回答