#' @title plot the outliers
#' @description The 'plot_outliers' function below draws a boxplot and a scatterplot of a numeric variable x and plots the values of the outliers (currently not offset, even if they overlap). For relatively small datasets, it can be a quick way to identify which outliers look reasonable and which are likely a result of transcription or measurement error, and thus should be either corrected or discarded.
#' @param x vector
#'
#'
#' @examples
#' plot_outliers(airquality$Wind, col = "darkgreen", main = "wind")
#' [Plot outliers and their values | modTools](https://modtools.wordpress.com/2020/03/13/plot-outliers-and-their-values/)
#' @rdname plot_outliers
#' @export
plot_outliers <- function(x, val_col = "blue", ...) {
par_in <- par(no.readonly = TRUE)
par(mfrow = c(1, 2))
bp <- boxplot(x, ...)
out <- bp$out
message(length(out), " outliers detected")
if (length(out) > 0) text(x = 0.5, y = bp$out, labels = round(out, 2), adj = 0, col = val_col)
plot(x, pch = 20)
if (length(out) > 0) text(x = 0.5, y = bp$out, labels = round(out, 2), adj = 0, col = val_col)
par(par_in)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.