【问题标题】:mosaic()-function of the vcd package: error in adding text in the cellsvcd 包的镶嵌()函数:在单元格中添加文本时出错
【发布时间】:2015-04-08 13:46:36
【问题描述】:

我使用vcd 包中的mosaic 函数创建了一个马赛克图。现在我想使用labeling_cells 添加一些注释。不幸的是,我得到一个错误。问题可能是它不是标准的Titanic 示例...

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 
       )

# 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

我遇到的另一个问题是盒子不适合标签。如果您对此有任何提示,也请告诉我!

这是我在这里的第一个问题,所以请原谅潜在的错误!

非常感谢!

【问题讨论】:

    标签: r categorical-data mosaic mosaic-plot


    【解决方案1】:

    在 vcd 1.4-4 中修复了上游,但请注意您可以简单地使用

    mosaic(data1, labeling = labeling_values)
    

    【讨论】:

      【解决方案2】:

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

      如果你知道它很容易解决它,但是:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-07-14
        • 2013-04-20
        • 2017-09-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多