mosaic() - vcd包的功能:在单元格中添加文本时出错

问题描述:

我已经使用vcd包中的mosaic函数创建了拼接图。现在我想用labeling_cells添加一些注释。不幸的是,我得到一个错误。这个问题可能是因为它不是标准Titanic例子...mosaic() - vcd包的功能:在单元格中添加文本时出错

library("grid"); library("vcd") 
dataset <- read.table("http://bit.ly/1aJTI1C") 

# prepare data for plot as a "Structured Contingency Table" 
data1 <- structable(dauer ~ groesse + ort, dataset) 

# basic plot 
mosaic(data1, 
     # separate the two elements of the plot 
     split_vertical = c(T, T, F), 

     # put the names in the right places and adds boxes 
     labeling_args = list(tl_labels = TRUE, 
          tl_varnames = FALSE, 
          boxes = TRUE), 
     # grip remains open 
     pop=FALSE 
     ) 

enter image description here

# structure that matches plot, but it does not help 
#match<-t(data1) 

# try to add labels 
labeling_cells(text = data1, clip = FALSE)(data1) 

这导致:

# Error in ifelse(abbreviate_varnames, sapply(seq_along(dn), function(i) abbreviate(dn[i], : 
# replacement has length zero 
# In addition: Warning message: 
# In rep(no, length.out = length(ans)) : 
# 'x' is NULL so the result will be NULL 

我有另一个问题在于,盒做不符合标签。如果您对此有所暗示,请让我知道!

这是我的第一个问题,所以请原谅可能的错误!

非常感谢!

是的,这很混乱,应该在labeling_cells()中修复。由于某些原因,标签中的数据应该是常规的table,而不是structable。我将与David,mosaic()的主要作者和软件包维护者一起提出这个问题。

如果你知道它可以很容易地解决它,但:

labeling_cells(text = as.table(data1), clip = FALSE)(as.table(data1)) 

mosaic labeling

在VCD 1.4-4上行修正,但请注意,你可以简单地使用

mosaic(data1, labeling = labeling_values)