- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 of vectors having different lengths in R?
If we have multiple vectors of different lengths then the boxplot for such vectors can be created by creating a single data frame using those vectors with a categorical column showing the name of the vectors and a numerical column having the corresponding values. Then boxplot function will be used as shown in the below example.
Consider the below vector x and y and create the data frame using them −
> x<-rpois(20,2) > y<-rpois(15,2) > df<-data.frame(X=c(x,y),Grp=rep(c("x","y"),times=c(20,15))) > df
X Grp 1 4 x 2 2 x 3 1 x 4 2 x 5 0 x 6 2 x 7 3 x 8 1 x 9 0 x 10 1 x 11 3 x 12 4 x 13 2 x 14 3 x 15 4 x 16 1 x 17 1 x 18 1 x 19 1 x 20 1 x 21 1 y 22 0 y 23 1 y 24 4 y 25 1 y 26 1 y 27 2 y 28 3 y 29 1 y 30 5 y 31 2 y 32 0 y 33 1 y 34 4 y 35 1 y
Creating the boxplot for groups in df −
- How to randomly split a vector into n vectors of different lengths in R?
- How to create transparent boxplot in R?
- How to create boxplot of grouped data in R?
- How to create combination of multiple vectors in R?
- How to create boxplot for matrix columns in R?
- How to create a horizontal boxplot in base R?
- How to create a barplot with one of the bars having different color in R?
- How to create a point chart in R with alternative points having different shape?
- How to find different elements between two string vectors in R?
- How to create a boxplot without frame in base R?
- How to create boxplot using ggplot2 without whiskers in R?
- How to create side-by-side boxplot in base R?
- How to create boxplot for multiple categories in base R?
- How to create boxplot in base R without axes labels?
- How to create a rectangle inside boxplot in base R?