EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

R Boxplot labels

By Priya PedamkarPriya Pedamkar

Secondary Sidebar
R programming Tutorial
  • Chart/graphs
    • Graphs in R
    • Bar Charts in R
    • Pie Chart in R
    • Histogram in R
    • Line Graph in R
    • Plot Function in R
    • Scatterplot in R
    • R Boxplot labels
  • Basic
    • What is R Programming Language
    • Careers in R Programming
    • Install R
    • List of R Packages
    • Introduction of R Tools Technology
    • R Programming Language
    • DataSet in R
    • What is RStudio?
    • R-studio-Functions
    • R Packages
    • Time series?in R
    • R Data Types
    • R for data science
    • R Operators
    • R Data Frame
    • R Analytics Tool
    • R Tree Package
    • Vectors in R
  • Control statement
    • If Statement in R
    • If Else Statement in R
    • Else if in R
    • Switch Statement in R
  • Loops
    • Loops in R
    • For Loop in R
    • Nested For Loop in R
    • While Loop in R
    • Next in R
  • Regression in R
    • Simple Linear Regression in R
    • Linear Regression in R
    • Multiple Linear Regression in R
    • Logistic Regression in R
    • Poisson Regression in R
    • OLS Regression in R
    • P-Value in Regression
  • Anova in R
    • ANOVA in R
    • One Way ANOVA in R
    • Two Way ANOVA in R
  • Data Structure
    • R list
    • Arrays in R
    • Data Frames in R
    • Factors in R
    • R Vectors
  • Advanced
    • Statistical Analysis with R
    • R String Functions
    • Data Exploration in R
    • R CSV Files
    • KNN Algorithm in R
    • Sorting in R
    • lm Function in R
    • Hierarchical Clustering in R
    • R Normal Distribution
    • Binomial Distribution in R
    • Decision Tree in R
    • GLM in R
    • Arima Model in R
    • Linear Model in R
    • Predict Function in R
    • Survival Analysis in R
    • Standard Deviation in R
    • Statistical Analysis in R
    • Predictive Analysis?in R
    • T-test in R
    • Database in R
  • Programs
    • Functions in R
    • Boxplot in R
    • R Program Functions
    • Factorial in R
    • Random Number Generator in R
  • Interview question
    • R Interview Questions

Related Courses

R Programming Certification Course

Statistical Analysis Course Training

All in One Data Science Courses

Home Data Science Data Science Tutorials R Programming Tutorial R Boxplot labels

R Boxplot labels

Introduction to Boxplot labels in R

Labels are used in box plot which are help to represent the data distribution based upon the mean, median and variance of the data set. R boxplot labels are generally assigned to the x-axis and y-axis of the boxplot diagram to add more meaning to the boxplot. The boxplot displays the minimum and the maximum value at the start and end of the boxplot. The mean label represented in the center of the boxplot and it also shows the first and third quartile labels associating with the mean position.

Plotting the boxplot graph

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

  • We need five valued input like mean, variance, median, first and third quartile.
  • Identifying if there are any outliers in the data.
  • Design the model to plot the data.

Parameters under boxplot() function

  1. formula: This parameter allows to spilt numeric values into several groups.
  2. Data:: Input data that contains either a data frame or a list.
  3. Subset: Optional vector parameter to specify a subset for plotting.
  4. xlab: x-axis annotation
  5. ylab: y-axis annotation.
  6. range: range specifies the plot extensions.
  7. action: specify what happens when there is a null value. Either ignore the response or the value.

Creating Random Data

We can create random sample data through the rnorm() function.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,992 ratings)

Let’s now use rnorm() to create random sample data of 10 values.

data<-data.frame(Stat1=rnorm(10,mean=3,sd=2))

Above command generates 10 random values with mean 3 and standard deviation=2 and stores it in the data frame.

When we print the data we get the below output.

Stat1

1  2.662022

2  2.184315

3  5.974787

4  4.536203

5  4.808296

6  3.817232

7  1.135339

8  1.583991

9  3.308994

10 4.649170

We can convert the same input(data) to the boxplot function that generates the plot.

R Boxplot Labels blank output 1

We add more values to the data and see how the plot changes.

data<-data.frame(Stat1=rnorm(10,mean=3,sd=2),
Stat2=rnorm(10,mean=4,sd=1),
Stat3=rnorm(10,mean=6,sd=0.5),
Stat4=rnorm(10,mean=3,sd=0.5))
boxplot(data)

Adding more random values and using it to represent a graph.

Below are values that are stored in the data variable.

STAT 1 STAT 2 STAT 3 STAT 4
3.795465 4.21864 5.827585 2.157315
0.911726 4.09119 6.260811 2.26594
3.707828 3.35987 5.88945 3.714557
0.115772 4.5123 5.934858 2.40645
0.697556 2.15945 6.81147 2.571304
5.129231 3.2698 6.250068 3.025175
5.404101 4.38939 5.670061 2.9901
1.455066 3.13059 5.692323 2.69693
0.868636 5.42311 5.415435 2.674768
2.14113 3.90728 6.206059 2.806656

Below is the boxplot graph with 40 values. We have 1-7 numbers on y-axis and stat1 to stat4 on the x-axis.

R Boxplot Labels blank output 3

We can change the text alignment on the x-axis by using another parameter called las=2.

Analyzing the Graph of R Boxplot labels

We have given the input in the data frame and we see the above plot.

To understand the data let us look at the stat1 values.

The plot represents all the 5 values. Starting with the minimum value from the bottom and then the third quartile, mean, first quartile and minimum value.

R Boxplot Labels blank output 3

R Boxplot Labels blank output 4

The above plot has text alignment horizontal on the x-axis.

Changing the Colour

In all of the above examples, We have seen the plot in black and white. Let us see how to change the colour in the plot.

We can add the parameter col = color in the boxplot() function.

data<-data.frame(Stat1=rnorm(10,mean=3,sd=2),
Stat2=rnorm(10,mean=4,sd=1),
Stat3=rnorm(10,mean=6,sd=0.5),
Stat4=rnorm(10,mean=3,sd=0.5))
boxplot(data,las=2,col="red")
data

Below we can see the plot output in red.

colour output 1

Using the same above code, We can add multiple colours to the plot.

data<-data.frame(Stat1=rnorm(10,mean=3,sd=2),
Stat2=rnorm(10,mean=4,sd=1),
Stat3=rnorm(10,mean=6,sd=0.5),
Stat4=rnorm(10,mean=3,sd=0.5))
boxplot(data,las=2,col=c("red","blue","green","yellow")
data

colour output 2

Adding Labels

We can add labels using the xlab,ylab parameters in the boxplot() function.

data<-data.frame(Stat1=rnorm(10,mean=3,sd=2),
Stat2=rnorm(10,mean=4,sd=1),
Stat3=rnorm(10,mean=6,sd=0.5),
Stat4=rnorm(10,mean=3,sd=0.5))
boxplot(data,las=2,xlab="statistics",ylab="random numbers",col=c("red","blue","green","yellow"))
data

colour output 3

By using the main parameter, we can add heading to the plot.

data<-data.frame(Stat1=rnorm(10,mean=3,sd=2),
Stat2=rnorm(10,mean=4,sd=1),
Stat3=rnorm(10,mean=6,sd=0.5),
Stat4=rnorm(10,mean=3,sd=0.5))
boxplot(data,las=2,xlab="statistics",ylab="random numbers",main="Random relation",notch=TRUE,col=c("red","blue","green","yellow"))
data

colour output 4

Notch parameter is used to make the plot more understandable. As medians of stat1 to stat4 don’t match in the above plot.

Advantages & Disadvantages of Box Plot

Below are the different Advantages and Disadvantages of the Box Plot:

Advantages

  • Summarizing large amounts of data is easy with boxplot labels.
  • Displays range and data distribution on the axis.
  • It indicates symmetry and skewness
  • Helps to identify outliers in the data.

Disadvantages

  • Can be used only for numerical data.
  • If there are discrepancies in the data then the box plot cannot be accurate.

Notes:

  1. Graphs must be labelled properly.
  2. Scales are important; changing scales can give data a different view.
  3. Comparing data with correct scales should be consistent

Conclusion – R Boxplot labels

The data grouping is made easy with the help of boxplots. Box plot supports multiple variables as well as various optimizations. We can also vary the scales according to data.

Boxplots can be used to compare various data variables or sets.

The usability of the boxplot is easy and convenient. We need consistent data and proper labels. Boxplots are often used in data science and even by sales teams to group and compare data. Boxplot gives insights on the potential of the data and optimizations that can be done to increase sales.

Boxplot is an interesting way to test the data which gives insights on the impact and potential of the data.

Recommended Articles

This is a guide to R Boxplot labels. Here we discuss the Parameters under boxplot() function, how to create random data, changing the colour and graph analysis along with the Advantages and Disadvantages. You may also look at the following article to learn more –

  1. Types of Data Visualization
  2. Data Warehouse Implementation
  3. Data Science Techniques
  4. What is Data Cube?
  5. Types of Plot Function in R
  6. Complete Guide to MATLAB Plot Function
Popular Course in this category
R Programming Training (13 Courses, 20+ Projects)
  13 Online Courses |  20 Hands-on Projects |  120+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Statistical Analysis Training (15 Courses, 10+ Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - R Programming Training (12 Courses, 20+ Projects) Learn More