1

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

Why?


Follow-up question: How to plot a mosaicplot for a 1x1 contingeny table?

1 Answers1

0

There appears to be too less variation in your data, if you set one element to FALSE it will work.

Reason: Method graphics:::mosaicplot.default contains the following lines (e.g. lines 12 and 13),

xdim <- maxdim[1L]
XP <- rep.int(0, xdim)

and maxdim seems to become numeric(0) probably due to one-dimensionality of your data:

ydim <- numeric(0)
rep.int(0, ydim)
# Error in rep.int(0, numeric(0)) : invalid 'times' value
jay.sf
  • 60,139
  • 8
  • 53
  • 110