Error in stripplot (was Re: [R] stripplot gets weird) (PR#195)
ripley@stats.ox.ac.uk
ripley@stats.ox.ac.uk
Thu, 13 May 1999 08:34:20 +0200 (MET DST)
[Moved to R-bugs, hence R-devel, as this is now a bug report. I have
fixed the stripplot bug.]
On Thu, 13 May 1999, David Scott wrote:
>
> After thinking that the name difference was a problem, or that attaching
> the dataframe was a problem, I think it might be something to do with
> internal representation of numbers:
More precisely, with rounding errors.
>
> aitken/Exam9> R
>
> R : Copyright 1999, The R Development Core Team
> Version 0.63.3 (March 6, 1999)
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type "?license" or "?licence" for distribution details.
>
> R is a collaborative project with many contributors.
> Type "?contributors" for a list.
>
> Type "demo()" for some demos, "help()" for on-line help, or
> "help.start()" for a HTML browser interface to help.
> Type "q()" to quit R.
>
>
> > impurity.df<-read.table("impurities.dat",header=T)
> > impurity.df
> supplier1 supplier2
> 1 3.8 1.8
> 2 3.5 2.2
> 3 4.1 1.3
> 4 2.5 5.1
> 5 3.6 4.0
> 6 4.3 4.7
> 7 2.1 3.3
> 8 2.9 4.3
> 9 3.2 4.2
> 10 3.7 2.5
> 11 2.8 5.4
> 12 2.7 4.6
> > supp.diff<-impurity.df$supplier1-impurity.df$supplier2
> > stripplot(supp.diff,method="stack")
> Warning in y + (unlist(xo) - 1) * offset * csize : longer object length
> is not a multiple of shorter object length
> Error: x and y lengths differ
> > dput(supp.diff)
> c(2, 1.3, 2.8, -2.6, -0.4, -0.4, -1.2, -1.4, -1, 1.2, -2.6, -1.9
> )
> > supp.diff<-c(2, 1.3, 2.8, -2.6, -0.4, -0.4, -1.2, -1.4, -1, 1.2, -2.6,
> -1.9
> + )
> > stripplot(supp.diff,method="stack")
> >
>
> Works!!!
>
> The bit of code inside stripplot that is playing up is intended to
> determine where there are repeated values, and create a sequence
> numbering the values:
> f <- function(x) seq(length(x))
> for (i in 1:n) {
> x <- groups[[i]]
> y <- rep(i, length(x))
> if (method == 2)
> y <- y + runif(length(y), -jitter, jitter)
> else if (method == 3) {
> xg <- split(x, factor(x))
> xo <- lapply(xg, f)
> x <- unlist(xg)
> y <- y + (unlist(xo) - 1) * offset * csize
Yes. On my machine
Browse[1]> x
-2.61 -2.62 -1.9 -1.4 -1.2 -1 -0.41 -0.42 1.2 1.3 2 2.8
-2.6 -2.6 -1.9 -1.4 -1.2 -1.0 -0.4 -0.4 1.2 1.3 2.0 2.8
Browse[1]> print(x, digits=17)
-2.61 -2.62 -1.9
-2.59999999999999964 -2.60000000000000053 -1.89999999999999947
-1.4 -1.2 -1
-1.39999999999999991 -1.19999999999999973 -1.00000000000000000
-0.41 -0.42 1.2
-0.39999999999999991 -0.40000000000000036 1.20000000000000018
1.3 2 2.8
1.29999999999999982 1.99999999999999978 2.79999999999999982
Browse[1]> factor(x)
[1] -2.6 -2.6 -1.9 -1.4 -1.2 -1 -0.4 -0.4 1.2 1.3 2 2.8
Levels: -2.6 -2.6 -1.9 -1.4 -1.2 -1 -0.4 -0.4 1.2 1.3 2 2.8
Browse[1]> unlist(xg)
-2.61 -2.62 -1.9 -1.4 -1.2 -1 -0.41 -0.42 1.2 1.3 2 2.8
-2.6 -2.6 -1.9 -1.4 -1.2 -1.0 -0.4 -0.4 1.2 1.3 2.0 2.8
Browse[1]> unlist(xo)
-2.61 -2.62 -2.61 -2.62 -1.9 -1.4 -1.2 -1 -0.41 -0.42 -0.41
1 2 1 0 1 1 1 1 1 2 1
-0.42 1.2 1.3 2 2.8
0 1 1 1 1
The main problem is that
Browse[1]> seq(0)
[1] 1 0
which is definitely wrong for here. stripplot should have
f <- function(x) seq(length=length(x))
En route, unlist gives very confusing labels, and I have added
use.names=FALSE.
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._