Hi all,
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
Thanks, Ludo
error in plot(table(c('a','a')))
3 messages · Ludo Pagie, R. Michael Weylandt, Rui Barradas
On Mon, Nov 26, 2012 at 2:41 PM, Ludo Pagie <l.pagie at nki.nl> wrote:
Hi all,
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)
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? Michael
Hello, Also gives an error in R 2.15.2 on Windows 7. 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.int(tbl.char1) [1] 1 2 > seq_along(tbl.char1) [1] 1 So the plot command will have 2 values for the x axis but just one for the y axis. seq_along seems to solve the matter. Hope this helps, Rui Barradas Em 26-11-2012 21:39, R. Michael Weylandt escreveu:
On Mon, Nov 26, 2012 at 2:41 PM, Ludo Pagie <l.pagie at nki.nl> wrote:
Hi all,
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)
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? Michael
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.