buhtz
buhtz

Reputation: 12152

How to use stripchart() in R?

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

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

Upvotes: 2

Views: 3395

Answers (1)

G5W
G5W

Reputation: 37641

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

Upvotes: 2

Related Questions