How to use stripchart() in R?

3.1k views Asked by At

I have problems to use stripchart() with the right placement of X- and Y-axes and with the correct direction of the stacked points.

This MWE imitates the steps I do with my real data

# stratify mtcars$mpg_strat
mtcars$mpg_strat <- cut(mtcars$mpg, breaks=seq(0,50,by=5))

stripchart(gear~mpg_strat,
           data=mtcars,
           method="stack",
           offset=.5, pch=20)

enter image description here

  • I want to have gear in the Y-axis and mpg_strat (stratified mpg) on the X-axis.
  • And the points should be stacked from bottom to top (vertical) and not from left to right (horizontal).

The example here doesn't produce it that way. When I try to switch mpg_strat~gear I get an error

Fehler in Summary.factor(c(5L, 4L, 4L, 3L, 4L, 4L, 4L, 3L, 3L, 3L, 5L,  : 
‘range’ not meaningful for factors
1

There are 1 answers

0
G5W On BEST ANSWER
stripchart(as.numeric(mpg_strat) ~ gear,
       data=mtcars,
       method="stack",
    xaxt = "n", 
    xlab="mpg_strat",
    ylab="gear",
       offset=.5, pch=20)
axis(1, at=3:7, labels=levels(mtcars$mpg_strat)[3:7])

enter image description here