- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 for multiple categories with long names in base R?
In base R, we use boxplot function to create the boxplots but if we have categorical vector and the corresponding numerical vector then the boxplot can be easily created. For this purpose, we should save those vectors in a data frame and use the $ operator and las = 2 argument to create the boxplot as shown in the below example.
Example
Consider the below vectors:
Countries<−sample(c("China","India","Canada","USA","Russia","Indonesia","Nepal"),5000,replace=TRUE) > Rate<−rnorm(5000,10,1)
Create the data frame using above vectors −
df<−data.frame(Countries,Rate) > head(df,20)
Output
Countries Rate 1 Russia 9.885246 2 Nepal 9.895285 3 USA 11.524113 4 Nepal 10.133226 5 Indonesia 9.711389 6 Russia 10.017597 7 Nepal 9.204832 8 Russia 8.436829 9 Russia 10.579013 10 Canada 7.984238 11 Canada 9.407908 12 Indonesia 9.047598 13 China 9.193126 14 India 8.524555 15 China 10.398155 16 India 6.926581 17 China 10.104521 18 Canada 10.178826 19 India 12.006973 20 Canada 10.371956
Creating boxplot for countries −
boxplot(df$Rate~df$Countries)
Output
Creating boxplot for countries by changing the printing direction of country’s name −
boxplot(df$Rate~df$Countries,las=2,xlab="")
Output
- Related Articles
- How to create boxplot for multiple categories in base R?
- How to create boxplot for categories with grey color palette using ggplot2 in R?
- How to create boxplot for a list object in base R?
- How to create boxplot for categories with grey color palette in reverse order using ggplot2 in R?
- How to create a horizontal boxplot in base R?
- How to create a classification model using svm for multiple categories in R?
- How to create boxplot with multiple factor levels using ggplot2 in R?
- How to create side-by-side boxplot in base R?
- How to create boxplot in base R without axes labels?
- How to create a boxplot without frame in base R?
- How to create a rectangle inside boxplot in base R?
- How to create a boxplot with log of the variable in base R?
- Create histogram with horizontal boxplot on top in base R.
- How to create multiple bar plots for varying categories with same width bars using ggplot2 in R?
- How to create boxplot in base R with higher width of the box lines?

Advertisements