- 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 change the X-axis labels for boxplots created by using boxplot function in R?
When we create boxplots for multiple categories in R using boxplot function, by default the X-axis labels are represented by numbers. But we might want to express the categories by their name. In this situation, we can use names argument along with the boxplot function.
Consider the below vectors that represent different categories and create the boxplot for these categories −
Example
Class1<-sample(101:200,1000,replace=TRUE) Class2<-sample(150:200,1000,replace=TRUE) Class3<-sample(180:200,1000,replace=TRUE) Class4<-sample(190:200,1000,replace=TRUE) boxplot(Class1,Class2,Class3,Class4)
Output
Now create the boxplot for the above categories by displaying their names on the X-axis −
Example
boxplot(Class1,Class2,Class3,Class4,names=c("Class1","Class2","Class3","Class4"))
Output
Example
boxplot(Class1,Class2,Class3,Class4,names=c("Class_I","Class_I","Class_III","Class_IV"))
Output
Advertisements