Bug 15118 - error in plot(table(c('a','a')))
error in plot(table(c('a','a')))
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Graphics
R 2.14.0
ix86 (32-bit) Linux
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-27 22:14 UTC by Ludo
Modified: 2012-12-25 02:03 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ludo 2012-11-27 22:14:58 UTC
there appears to be something strange with the plotting of tables of 1
dimension; if I attempt to make a plot of a table of characters with only
1 value I get an error (Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ). With more than one value I don't get
errors, neither with integers (even if only 1 value):

tbl.char1 <- table(c('a','a'))
tbl.char2 <- table(c('a','a','b'))
tbl.int1 <- table(c(1,1))

# error:
plot(tbl.char1)

# no errors:
plot(tbl.char2)
plot(tbl.int1)


sessionInfo()


R version 2.14.0 (2011-10-31)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C                 LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base




See also mails on the R-help mailing list with same subject for suggestions. 

Thanks, Ludo
Comment 1 Ludo 2012-11-29 08:40:50 UTC
Here's the last mail in the R-help/R-devel mail list discussion with an overview of the discussion and suggested solution:

R. Michael Weylandt michael.weylandt@gmail.com
3:22 PM (17 hours ago)

to R, Rui, l.pagie 
Should I file an issue for this in the bug tracker?

Slighly rearranged discussion with reproducible example follows on below.



> Em 26-11-2012 21:39, R. Michael Weylandt escreveu:
>>
>> On Mon, Nov 26, 2012 at 2:41 PM, Ludo Pagie <l.pagie@nki.nl> wrote:
>>> tbl.char1 <- table(c('a','a'))
>>> tbl.char2 <- table(c('a','a','b'))
>>> tbl.int1 <- table(c(1,1))
>>>
>>> # error:
>>> plot(tbl.char1)
>>>
>>> # no errors:
>>> plot(tbl.char2)
>>> plot(tbl.int1)
>>>
>> Confirmed in current R-devel. It seems to arise from plot.table's use
>> of seq.int(x) when the dimnames of the table are not integers. I'm not
>> sure if this shouldn't be seq_along(x) instead, but I'm not sure I
>> totally follow the internal logic, so perhaps someone can offer second
>> opinion?

On Mon, Nov 26, 2012 at 11:34 PM, Rui Barradas <ruipbarradas@sapo.pt> wrote:
>  I'd change "when the dimnames of the table are not integers "
> to not numeric as that's what the code for plot.table tests. And it
> seems to come from seq.int, since with table value
> of 2, seq.int produces a vector of length 2 but the table length is 1:
>
> seq_along seems to solve the matter.
Comment 2 Duncan Murdoch 2012-12-25 02:03:02 UTC
Thanks, now fixed in R-devel and soon R-patched.