3

How would you add points to a several boxplots beside one another of varying lengths?

boxplot(box1, box2, box3, box4, beside=T, col=c("grey100", "grey70", "grey50", "grey70"), names=c("box1", "box2", "box3", "box4"), main="all the boxes", las=2)

If I put in something with

points() 

function I can't add in more than one and if I put them in separately they will be added to ALL the boxplots and I only want to see the corresponding points.

zx8754
  • 52,746
  • 12
  • 114
  • 209
user3324491
  • 539
  • 1
  • 4
  • 14
  • 1
    would you add some data and point to some known example of what you want to achieve? I'd recommend you [this](http://stackoverflow.com/q/5963269/640783) reading on how to make a reproducible example – Paulo E. Cardoso Oct 15 '15 at 16:45
  • 1
    Are you looking for something like this: `boxplot(mpg ~ carb, data=mtcars); points(mtcars$carb, mtcars$mpg)`. As @PauloCardoso said, it will be easier to help you if you provide sample data that runs with your code. – eipi10 Oct 15 '15 at 17:30

1 Answers1

6

Try:

ndata=mtcars[mtcars$carb%in%c(1:4),]
boxplot(mpg ~ carb, data=ndata 
        , beside=T,
        col=c("grey100", "grey70", "grey50", "grey70"),
        names=c("box1", "box2", "box3", "box4"),
        main="all the boxes", las=2)

points(factor(ndata$carb), ndata$mpg,col=3)
points(3,30,col=4,pch=13)
text (3.5,30,"Oops",pos = 4)

enter image description here

Robert
  • 5,038
  • 1
  • 25
  • 43