如何为 1x1 列联表绘制马赛克图? [英] How to plot a mosaicplot for a 1x1 contingency table?

查看:64
本文介绍了如何为 1x1 列联表绘制马赛克图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绘制 1×1 列联表会返回错误:

dat <- read.table(textConnection('富吧真真假真真假'), header = TRUE, colClasses=c('logical', 'logical'))马赛克图(表(数据))rep.int(0, ydim) 中的错误:无效的时间"值

Plotting a 1-by-1 contingency table returns an error:

dat <- read.table(textConnection('
foo bar
TRUE TRUE
TRUE TRUE
'), header = TRUE, colClasses=c('logical', 'logical'))
mosaicplot(table(dat))

Error in rep.int(0, ydim) : invalid 'times' value

As I learned, the code in the mosaicplot function doesn't allow to plot a 1-by-1-table. But then, how do I plot a mosaicplot of that table?


Background.

I am plotting a series of dynamically created tables, some of which sometimes happen to have only one column and one row, at other times they have more dimensions. Having an undivided rectangle in that series of mosaicplots is valuable information and easily grasped in that visual representation.

解决方案

One possibility is to coerce the variables to be plotted to factor and specify the possible outcomes in levels (in the desired order). Then zero count cells will be represented as thin lines.

dat[] = lapply(dat, factor, levels = c(TRUE, FALSE))
mosaicplot(table(dat))

这篇关于如何为 1x1 列联表绘制马赛克图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆