
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create boxplot with horizontal lines on the minimum and maximum in R?
A boxplot shows the minimum, first quartile, median, third quartile, and maximum. When we create a boxplot with ggplot2 it shows the boxplot without horizontal lines on the minimum and maximum, if we want to create the horizontal lines we can use stat_boxplot(geom= 'errorbar') with ggplot function of ggplot2.
Example
Consider the below data frame −
set.seed(101) Gender <-rep(c("Male","Female"),times=100) Salary <-sample(20000:50000,200,replace=TRUE) df <-data.frame(Gender,Salary) head(df,20)
Output
Gender Salary 1 Male 44392 2 Female 22872 3 Male 33741 4 Female 30334 5 Male 36374 6 Female 39664 7 Male 25561 8 Female 41854 9 Male 27996 10 Female 23003 11 Male 44890 12 Female 33557 13 Male 35202 14 Female 48287 15 Male 49826 16 Female 25919 17 Male 41000 18 Female 34687 19 Male 46978 20 Female 22530
Creating a simple boxplot −
Example
library(ggplot2) ggplot(df,aes(Gender,Salary))+geom_boxplot()
Output
Creating the boxplot with horizontal lines on the minimum and maximum −
Example
ggplot(df,aes(Gender,Salary))+geom_boxplot()+stat_boxplot(geom='errorbar')
Output
- Related Questions & Answers
- Create histogram with horizontal boxplot on top in base R.
- How to create a horizontal boxplot in base R?
- How to create boxplot in base R with higher width of the box lines?
- How to create horizontal lines with two different colors after a threshold in R?
- How to remove end lines from a boxplot in R?
- Create line chart for mean covered with minimum and maximum in R.
- How to create transparent boxplot in R?
- How to create horizontal histogram in R?
- How to create horizontal lines for each bar in a bar plot of base R?
- How to create a boxplot using ggplot2 with aes_string in R?
- How to create a circle with vertical lines in R?
- How to create a boxplot with log of the variable in base R?
- How to create boxplot using mean and standard deviation in R?
- How to add a horizontal line in a boxplot created in base R?
- How to create a boxplot with outliers of larger size in R?
Advertisements