I would like to plot each column of a matrix as a boxplot and then label the outliers in each boxplot as the row name they belong to in the matrix. To use an example:
vv=matrix(c(1,2,3,4,8,15,30),nrow=7,ncol=4,byrow=F)
rownames(vv)=c("one","two","three","four","five","six","seven")
boxplot(vv)
I would like to label the outlier in each plot (in this case 30) as the row name it belongs to, so in this case 30 belongs to row 7. Is there an easy way to do this? I have seen similar questions to this asked but none seemed to have worked the way I want it to.
boxplot() does not identify outliers, but it is quite easy to program, as boxplot. stats() supplies a list of outliers.. You can add a density plot (barcode plot) to the boxplot.
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).
To highlight outliers in a boxplot, we can create the boxplot with the help of Boxplot function of car package by defining the id.
Labels are used in box plot which are help to represent the data distribution based upon the mean, median and variance of the data set. R boxplot labels are generally assigned to the x-axis and y-axis of the boxplot diagram to add more meaning to the boxplot.
There is a simple way. Note that b in Boxplot in following lines is a capital letter.
library(car)
Boxplot(y ~ x, id.method="y")
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