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
To change the color of outliers in base R boxplot, we can use outcol argument in boxplot function.
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.
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).
Removing/ ignoring outliers is generally not a good idea because highlighting outliers is generally one of the advantages of using box plots.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With