[英]mosaic()-function of the vcd package: error in adding text in the cells
I have created a mosaic plot using mosaic
function in the vcd
package. 我在
vcd
包中使用mosaic
功能创建了一个马赛克图。 Now I wish to add some annotations using labeling_cells
. 现在我想使用
labeling_cells
添加一些注释。 Unfortunately, I get an error. 不幸的是,我收到了一个错误。 The problem might be that it is not the standard
Titanic
example... 问题可能是它不是标准的
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)
This results in: 这导致:
# 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
Another problem I have is that the boxes do not fit the labels. 我遇到的另一个问题是盒子不适合标签。 If you have a hint for that just let me know as well!
如果您有提示,请告诉我!
It's my first question here, so please excuse potential errors! 这是我的第一个问题,请原谅潜在的错误!
Thanks a lot! 非常感谢!
修复了vcd 1.4-4中的上游,但请注意您可以简单地使用
mosaic(data1, labeling = labeling_values)
Yes, this is quite confusing and ought to be fixed in labeling_cells()
. 是的,这很混乱,应该在
labeling_cells()
修复。 For some reason the data in the labeling should be a regular table
, not a structable
. 由于某种原因,标签中的数据应该是常规
table
,而不是structable
。 I'll raise this with David, the principal author of mosaic()
and package maintainer. 我将与
mosaic()
和包维护者的主要作者大卫提出这个问题。
If you know it it's easy to work around it, though: 如果你知道它很容易解决它,但是:
labeling_cells(text = as.table(data1), clip = FALSE)(as.table(data1))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.