me_overfolwn
me_overfolwn

Reputation: 64

abline in boxplot only on canvas

I wanted to add an abline() to a boxplot, but it is drawn all over the graphic and not just in the canvas. Is there a workaround?

boxplot(mpg ~ cyl, data = mtcars, main = "Car Milage Data",
        xlab = "Number of Cylinders", ylab = "Miles Per Gallon") 
abline(v = 2.5, col = "grey", lty = 2)

boxplot

Upvotes: 1

Views: 166

Answers (1)

me_overfolwn
me_overfolwn

Reputation: 64

Thanks to Darren Tsai whose suggestion in a comment:

Try par(xpd = F) and run your code again.

fixed the problem.

Upvotes: 1

Related Questions