[R] Data scaled by lattice::stripplot

Peter Ehlers ehlers at ucalgary.ca
Fri Jun 29 13:45:22 CEST 2012


On 2012-06-28 21:06, meonline wrote:
> For the following example,
>
>> library(lattice)
>> df<-data.frame(i=1:100,p=runif(100),id=rep(c('a','b'),100))
>> summary(df[,'p'])
>     Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
> 0.01165 0.33580 0.57520 0.53290 0.74540 0.98610
>> stripplot(p~i|id,df)
>
> The plot that is output is as expected with the exception that the values
> are scaled by a factor of 100 in the plot (and the yaxis has too many
> labels) -- see attached screenshot.
>
> I'm running R.2.10 under Ubuntu 10.04.
>
> Why does this happen and how do I get the stripplot to plot the values as
> they are in the data (from 0 to 1)?

You need to understand what a stripplot is for; as the
help page says: "stripplot produces one-dimensional
scatterplots".

It's usually used to compare several such one-dim plots
for different levels of a factor variable; see the
example on the help page or the examples on the help
page for stripchart which does the same thing using
traditional graphics. Using your data, try:

  stripplot(p ~ id, data = df)

With stripplot(p ~ i | id, df), lattice coerces 'p' to
a factor, assigning levels '1', '2', ..., '100' since
you have 100 different values. It then plots 100
strips _horizontally_ (you can't tell since each
plot has only a single value). You get 100 labels on
the y-axis. No scaling has taken place.

The measured variable is taken to be 'i'. Its values
are also 1-100 and that's what you see on the x-axis.

Try adding 'horizontal = FALSE' to the command:

   stripplot(p ~ i | id, data = df, horizontal = FALSE)

This will give you 100 _vertical_ strips, using 'i' as
the factor variable. The measured variable is then 'p'
and you'll see the values you were expecting.

But I suspect that you never wanted a stripplot at all.

Peter Ehlers



More information about the R-help mailing list