Labeled outliers in R boxplot
[This article was first published on macsci, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Boxplots are a good way to get some insight in your data, and while R provides a fine ‘boxplot’ function, it doesn’t label the outliers in the graph. However, with a little code you can add labels yourself:Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The numbers plotted next to the outliers indicate the row number of your original dataframe. Admitted, it could look nicer, but it’s enough to find your outliers back in your data.
It’s done by this code:
#create boxplot
boxdata <- with(data,boxplot(dependent ~ condition1 * condition2, range=4))
#for each outlier in boxdata
for(i in 1:length(boxdata$group)){
#add text to the boxplot
text(boxdata$group[i], boxdata$out[i], which(data$dependent==boxdata$out[i]),pos=4)
}
You can download the code here.
To leave a comment for the author, please follow the link and comment on their blog: macsci.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.