Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of outliers in boxplot with boxplot()?

Tags:

r

boxplot

I am trying to color the outliers in my boxplot in black. I managed to color the box in grey but I cant figure out how to color outliers. (the white points on the graph)

boxplot(y1$Frequency..times., col="grey")

Thanks in advance for the help enter image description here

like image 373
user1783504 Avatar asked Sep 08 '13 16:09

user1783504


People also ask

How do you change the color of an outlier in a box plot?

To change the color of outliers in base R boxplot, we can use outcol argument in boxplot function.

How do you color Boxplots?

Coloring Boxplot by Variable We can color a boxplot like this using color argument inside aesthetics function aes() as shown below. Here, we color the lines of boxplot by specifying color=age_group. ggplot2 also makes a legend for colors and variable used in the plot.

How do you find the outlier on a box plot?

When reviewing a box plot, an outlier is defined as a data point that is located outside the whiskers of the box plot. For example, outside 1.5 times the interquartile range above the upper quartile and below the lower quartile (Q1 - 1.5 * IQR or Q3 + 1.5 * IQR).

Should I remove outliers from boxplot?

Removing/ ignoring outliers is generally not a good idea because highlighting outliers is generally one of the advantages of using box plots.


1 Answers

boxplot(y1$Frequency..times., col="grey", outcol="red")

or preferably, but longer

boxplot(y1$Frequency..times., col="grey", pars=list(outcol="red"))

It's all in the manual, but it can be hard to find if you aren't that experienced. When reading ?boxplot, notice the description of the pars argument.

pars

a list of (potentially many) more graphical parameters, e.g., boxwex or outpch; these are passed to bxp (if plot is true); for details, see there.

?bxp in turn it tells you that there is a number of arguments that control the appearance of outliers.

pars, ...

outlty, outlwd, outpch, outcex, outcol, outbg:

outlier line type, line width, point character, point size expansion, color, and background color. The default outlty = "blank" suppresses the lines and outpch = NA suppresses points.

like image 110
Backlin Avatar answered Nov 05 '22 00:11

Backlin