简体   繁体   English

马赛克情节(vcd包) - 传奇的位置

[英]Mosaic plot (vcd package) - position of legend

I'm trying to make a mosaic plot with the vcd package, and i'm having an hard time understanding how to configure some settings of the plot. 我正在尝试用vcd包制作马赛克图,我很难理解如何配置图的一些设置。

library(vcd)
library(RColorBrewer)
mydf <- structure(list(A=structure(c(7L,6L,7L,6L,7L,1L,5L,4L,7L,6L,6L,6L,6L,6L,
                                     3L,6L,6L,6L,5L,3L),
                           .Label=c("a","b","c","d","e","f","g","h","i"),
                           class="factor"),
               B=structure(c(3L,2L,1L,1L,3L,3L,3L,3L,2L,3L,3L,1L,3L,
                                3L,3L,3L,3L,3L,3L,3L),
                           .Label=c("a","b","c"),
                           class="factor")),
          .Names=c("A","B"),
          row.names=c(1L,  2L,  3L,  4L,  5L,  6L,  7L,  8L,  9L, 
                      10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L),
          class="data.frame")

mosaic( ~ A + B, data=mydf, highlighting="A", 
        highlighting_fill=brewer.pal(9, "Set3"))

The legend of the different levels of the A variable are on the top of the plot, which is not ver helpful since the category "a", of variable B does not have all those levels. A变量的不同级别的图例位于图的顶部,这不是有用的,因为变量B的类别“a”没有所有这些级别。 I would like the legend to be in the bottom to be together with the category that has all the levels in the legend. 我希望图例在底部与图例中包含所有级别的类别一起使用。

From ?labeling I learned there were several "behind the scenes" functions that accept arguments from mosaic and tried a couple of changes: 从?标签我了解到有几个“幕后”功能接受马赛克的参数并尝试了一些变化:

?labeling

I believe this is closer to what you were hoping for: 我相信这更接近你所希望的:

 mosaic( ~ A + B, data=mydf, highlighting="A", 
      highlighting_fill=brewer.pal(9, "Set3"),
      labeling_args=list(tl_labels =c(TRUE, FALSE) ) )

Sets the row labels to the bottom and uses the lower cell locations for placement. 将行标签设置为底部,并使用较低的单元格位置进行放置。 (Still have overlap of 'h' and 'i' but they can even be resoved, whereas you had overlap of ae before.) (仍然有'h'和'i'的重叠,但它们甚至可以被重新调整,而之前你有重叠的ae。)

在此输入图像描述

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

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