David_Authors_Books
David_Authors_Books

Reputation: 39

How to remove box and whiskers from plot() function in R?

I'm trying to do a very simple plot using the plot() function in R where I plot out the weights and diets of chicks in a stratified plot. For other simple plots like this I've been able to just use the plot() function and it's gone fine. But for some reason, R insists on plotting this as a box-and-whiskers chart instead of plotting all the values themselves. I've tried many different solutions I've found on the Web, from box=FALSE to box=0 to bty="n" to type="p" but nothing works. R always plots it as a box-and-whiskers chart. I can use whisklty=0 to get rid of the whiskers, but nothing I've tried (including all possible combinations of the above solutions) will replace the boxes with the actual values I want.

Upvotes: 1

Views: 598

Answers (1)

eipi10
eipi10

Reputation: 93761

If the x-axis data is categorical, plot will return a boxplot by default. You could run plot.default() instead of plot() and that will give you a plot of points.

Compare, for example:

plot(iris$Species, iris$Petal.Width)

plot.default(iris$Species, iris$Petal.Width)

If you type methods(plot) in the console, you'll see all of the different kinds of plots the plot function returns, depending on what type of object you give it. plot.default is the "method" that gets dispatched when you provide plot with two columns of numbers. plot.factor gets dispatched when the y-values are numeric and the x-values are categorical (run ?plot.factor for details). If you do plot(table(mtcars$vs, mtcars$cyl)) the plot.table method gets dispatched. And so on.

Upvotes: 2

Related Questions