SlideShare a Scribd company logo
1 of 30
www.r-squared.in/git-hub
R2
Academy
Data Visualization With R:
Univariate Bar Plots
R2
AcademyCourse Material
Slide 2
All the material related to this course are available on our website
Scripts can be downloaded from GitHub
Videos can be viewed on our Youtube Channel
R2
AcademyTable Of Contents
Slide 3
➢ Objectives
➢ Introduction
➢ Simple bar plot
➢ Bar width
➢ Space between bars
➢ Bar Labels
➢ Horizontal Bars
➢ Density of shading lines
➢ Angle of shading lines
➢ Color
➢ Legend
➢ Border color
➢ Display/Hide vertical axes
➢ Display/Hide labels
➢ Modify font size of numeric (vertical Y) axis
➢ Modify font size of categorical(horizontal X) axis
➢ Line Type of horizontal axis
➢ Modify values of numeric (vertical Y) axis
➢ Summary
R2
AcademyObjectives
Slide 4
➢ Create univariate bar plots
➢ Modify width, space and color of bars
➢ Add legend to the plot
➢ Modify appearance of the axis
Note: In this tutorial, we use the Graphics package.
R2
AcademyIntroduction
Slide 5
A bar chart or bar graph is a chart that presents Grouped data with rectangular bars with lengths proportional to the
values that they represent. The bars can be plotted vertically or horizontally. A vertical bar chart is sometimes called a
column bar chart.
- Wikipedia
R2
AcademySimple Bar Plot
Slide 6
In the Graphics package, the barplot function
is used to create bar plots. You can learn more
about this function from the help pages:
help(barplot)
To create a bar plot, we first tabulate the data
using the table function and then use the
tabulated data as the input.
# basic bar plot
data <- table(mtcars$cyl)
barplot(data)
R2
AcademyBar Width
Slide 7
The width of the bars can be modified using the
width option in the barplot function.
In the below example, we specify the width of
the middle bar to be twice that of the other two
bars.
# specify width of bars
data <- table(mtcars$cyl)
barplot(data, width = c(1, 2, 1))
R2
AcademySpace Between Bars
Slide 8
The space between the bars can be modified
using the space option in the barplot
function.
In the below example, we specify the space
between the bars to be 1.5
# specify space between bars
data <- table(mtcars$cyl)
barplot(data, space = 1.5)
R2
AcademySpace Between Bars
Slide 9
R2
AcademyLabels
Slide 10
The labels of the bars can be modified using
the names.arg option in the barplot function.
The names must be specified using a character
vector, the length of which should be equal to
the number of bars.
# specify labels for bars
data <- table(mtcars$cyl)
barplot(data, names.arg = c("Four",
"Six", "Eight"))
R2
AcademyHorizontal Bars
Slide 11
Horizontal bar plots can be created using the
horiz option in the barplot function. If it is
set to TRUE, horizontal bars are drawn else
vertical bars are drawn.
Note: The default value of this option is FALSE.
# horizontal bars
data <- table(mtcars$cyl)
barplot(data, horiz = TRUE)
R2
AcademyShading Lines (Density)
Slide 12
Shading lines can be drawn on the bars using
the density option in the barplot function. It
takes positive values and the density of the
lines increases in proportion to the values
specified.
Note: The default value of this option is NULL.
Lines will not be drawn if negative values are
specified.
# specify density of shading lines
data <- table(mtcars$cyl)
barplot(data, density = 10)
R2
AcademyShading Lines (Density)
Slide 13
R2
AcademyShading Lines (Angle)
Slide 14
The angle of the shading lines drawn on the
bars can be modified using the angle option in
the barplot function. It takes both positive and
negative values.
# specify angle of shading lines
data <- table(mtcars$cyl)
barplot(data, density = 10, angle = 60)
R2
AcademyShading Lines (Angle)
Slide 15
R2
AcademyColor
Slide 16
The color of the bars can be modified using the
col option in the barplot function. The color
can be mentioned in RGB or hexadecimal
format as well.
# specify color of bars
data <- table(mtcars$cyl)
barplot(data, col = "blue")
R2
AcademyColor
Slide 17
Different colors for the bars can be created by
specifying a character vector consisting of the
names of the colors. If the number of colors
mentioned is less than the number of bars, the
colors will be repeated.
# specify different color for bars
data <- table(mtcars$cyl)
barplot(data, col = c("red", "green",
"blue"))
R2
AcademyLegend
Slide 18
A legend can be added using the legend.text
option. If it is set to TRUE, a legend is added
based on the values associated with the bars.
We can also specify a character vector in which
case the legend will be created on the basis of
the input specified. We will explore legends in
more detail in a separate tutorial.
# specify legend
data <- table(mtcars$cyl)
barplot(data, col = c("red", "green",
"blue"), legend.text = TRUE)
R2
AcademyBorder Color
Slide 19
The border color of the bars can be modified
using the border option in the barplot
function. The color can be mentioned in RGB or
hexadecimal format as well.
# specify border color of bars
data <- table(mtcars$cyl)
barplot(data, border = "blue")
R2
AcademyBorder Color
Slide 20
Different colors for the borders can be created
by specifying a character vector consisting of
the names of the colors. If the number of colors
mentioned is less than the number of bars, the
colors will be repeated.
# specify different border color
data <- table(mtcars$cyl)
barplot(data, border = c("red",
"green", "blue"))
R2
AcademyTitle, Axis Labels & Range
Slide 21
We can add a title and modify the axis labels
and range using the options we learnt in the
earlier tutorials.
# specify title, axis labels and range
data <- table(mtcars$cyl)
barplot(data, col = c("red", "green", "blue"),
main = "Frequency of Cylinders",
xlab = "Number of Cylinders",
ylab = "Frequency", ylim = c(0, 20))
R2
AcademyAxes
Slide 22
The vertical axes is not drawn if the axes option is set to FALSE. The default value is TRUE and hence a
vertical axes is always drawn unless specified otherwise.
R2
AcademyAxis Names
Slide 23
The labels of the bars are not added if the axisnames option is set to FALSE. The default value is TRUE
and hence the labels are always added unless specified otherwise.
R2
AcademyNumeric Axis Font Size
Slide 24
The font size of the
numeric axis can
be modified using
the cex.axis
option.
R2
AcademyLabels Font Size
Slide 25
The font size of the
labels can be
modified using the
cex.names option.
R2
AcademyAxis Line Type
Slide 26
A line type for the
horizontal axis can
be specified using
axis.lty option.
R2
AcademyOffset
Slide 27
The values of the
numeric (vertical Y)
axis can be
modified using the
offset option.
R2
Academy
Slide 28
● Bar plots can be created using the barplot() function.
● Tabulate the data using the table() function before plotting.
● Modify the width of the bars using the width option.
● Modify the space between the bars using the space option.
● Modify the labels of the bars using the names.arg option.
● Create horizontal bars using the horiz option.
● Add shading lines using the density option and modify the angle of the lines using the angle
option.
● Add color to the bars using the col and border options.
● Add legend to the plot using the legend.text option.
● Display/hide the numeric axis using the axes option.
● Display/hide the labels using the axis.names option.
● Modify font size of the numeric axis using the cex.axis option.
● Modify font size of the labels using the cex.names option.
● Modify line type of the horizontal axis using the axis.lty option.
● Modify values of the numeric axis using the offset option.
Summary
R2
AcademyNext Steps...
Slide 29
In the next module:
✓ Bivariate Bar Plots
✓ Stacked Bar Plots
✓ Grouped Bar Plots
R2
Academy
Slide 30
Visit Rsquared Academy
for tutorials on:
→ R Programming
→ Business Analytics
→ Data Visualization
→ Web Applications
→ Package Development
→ Git & GitHub

More Related Content

What's hot

Statistical Analysis with R -I
Statistical Analysis with R -IStatistical Analysis with R -I
Statistical Analysis with R -IAkhila Prabhakaran
 
Graph Coloring and Its Implementation
Graph Coloring and Its ImplementationGraph Coloring and Its Implementation
Graph Coloring and Its ImplementationIJARIIT
 
Graph Coloring : Greedy Algorithm & Welsh Powell Algorithm
Graph Coloring : Greedy Algorithm & Welsh Powell AlgorithmGraph Coloring : Greedy Algorithm & Welsh Powell Algorithm
Graph Coloring : Greedy Algorithm & Welsh Powell AlgorithmPriyank Jain
 
Probabilistic models (part 1)
Probabilistic models (part 1)Probabilistic models (part 1)
Probabilistic models (part 1)KU Leuven
 
Data visualization using R
Data visualization using RData visualization using R
Data visualization using RUmmiya Mohammedi
 
Types of parsers
Types of parsersTypes of parsers
Types of parsersSabiha M
 
Introduction to Regression Analysis
Introduction to Regression AnalysisIntroduction to Regression Analysis
Introduction to Regression AnalysisMinha Hwang
 
Algorithms explained
Algorithms explainedAlgorithms explained
Algorithms explainedPIYUSH Dubey
 
Graph coloring and_applications
Graph coloring and_applicationsGraph coloring and_applications
Graph coloring and_applicationsmohammad alkhalil
 
Bellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
Bellman-Ford-Moore Algorithm and Dijkstra’s AlgorithmBellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
Bellman-Ford-Moore Algorithm and Dijkstra’s AlgorithmFulvio Corno
 

What's hot (20)

Backtracking
BacktrackingBacktracking
Backtracking
 
Graph coloring
Graph coloringGraph coloring
Graph coloring
 
Graph coloring
Graph coloringGraph coloring
Graph coloring
 
Statistical Analysis with R -I
Statistical Analysis with R -IStatistical Analysis with R -I
Statistical Analysis with R -I
 
Graph Coloring and Its Implementation
Graph Coloring and Its ImplementationGraph Coloring and Its Implementation
Graph Coloring and Its Implementation
 
Daa notes 3
Daa notes 3Daa notes 3
Daa notes 3
 
Graph Coloring : Greedy Algorithm & Welsh Powell Algorithm
Graph Coloring : Greedy Algorithm & Welsh Powell AlgorithmGraph Coloring : Greedy Algorithm & Welsh Powell Algorithm
Graph Coloring : Greedy Algorithm & Welsh Powell Algorithm
 
AI: Learning in AI
AI: Learning in AI AI: Learning in AI
AI: Learning in AI
 
Probabilistic models (part 1)
Probabilistic models (part 1)Probabilistic models (part 1)
Probabilistic models (part 1)
 
Data visualization using R
Data visualization using RData visualization using R
Data visualization using R
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Types of parsers
Types of parsersTypes of parsers
Types of parsers
 
Introduction to Regression Analysis
Introduction to Regression AnalysisIntroduction to Regression Analysis
Introduction to Regression Analysis
 
Graph coloring Algorithm
Graph coloring AlgorithmGraph coloring Algorithm
Graph coloring Algorithm
 
N queens using backtracking
N queens using backtrackingN queens using backtracking
N queens using backtracking
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 
Graph coloring problem
Graph coloring problemGraph coloring problem
Graph coloring problem
 
Algorithms explained
Algorithms explainedAlgorithms explained
Algorithms explained
 
Graph coloring and_applications
Graph coloring and_applicationsGraph coloring and_applications
Graph coloring and_applications
 
Bellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
Bellman-Ford-Moore Algorithm and Dijkstra’s AlgorithmBellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
Bellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
 

Viewers also liked

RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRsquared Academy
 
R Markdown Tutorial For Beginners
R Markdown Tutorial For BeginnersR Markdown Tutorial For Beginners
R Markdown Tutorial For BeginnersRsquared Academy
 
Data visualization for development
Data visualization for developmentData visualization for development
Data visualization for developmentSara-Jayne Terp
 
Data Visualization With R: Introduction
Data Visualization With R: IntroductionData Visualization With R: Introduction
Data Visualization With R: IntroductionRsquared Academy
 
Data Visualization With R: Learn To Modify Title, Axis Labels & Range
Data Visualization With R: Learn To Modify Title, Axis Labels & RangeData Visualization With R: Learn To Modify Title, Axis Labels & Range
Data Visualization With R: Learn To Modify Title, Axis Labels & RangeRsquared Academy
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data TypesRsquared Academy
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to MatricesRsquared Academy
 
Data Visualization: Introduction to Shiny Web Applications
Data Visualization: Introduction to Shiny Web ApplicationsData Visualization: Introduction to Shiny Web Applications
Data Visualization: Introduction to Shiny Web ApplicationsOlga Scrivner
 

Viewers also liked (10)

RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
 
R Markdown Tutorial For Beginners
R Markdown Tutorial For BeginnersR Markdown Tutorial For Beginners
R Markdown Tutorial For Beginners
 
Data visualization for development
Data visualization for developmentData visualization for development
Data visualization for development
 
Data Visualization With R: Introduction
Data Visualization With R: IntroductionData Visualization With R: Introduction
Data Visualization With R: Introduction
 
Data Visualization With R: Learn To Modify Title, Axis Labels & Range
Data Visualization With R: Learn To Modify Title, Axis Labels & RangeData Visualization With R: Learn To Modify Title, Axis Labels & Range
Data Visualization With R: Learn To Modify Title, Axis Labels & Range
 
Insights From Data Visualization - Stephen Lett (Procter & Gamble)
Insights From Data Visualization - Stephen Lett (Procter & Gamble)Insights From Data Visualization - Stephen Lett (Procter & Gamble)
Insights From Data Visualization - Stephen Lett (Procter & Gamble)
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data Types
 
Data Visualization With R
Data Visualization With RData Visualization With R
Data Visualization With R
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
 
Data Visualization: Introduction to Shiny Web Applications
Data Visualization: Introduction to Shiny Web ApplicationsData Visualization: Introduction to Shiny Web Applications
Data Visualization: Introduction to Shiny Web Applications
 

Similar to R Data Visualization Tutorial: Bar Plots

Data Visualization With R: Learn To Modify Color Of Plots
Data Visualization With R: Learn To Modify Color Of PlotsData Visualization With R: Learn To Modify Color Of Plots
Data Visualization With R: Learn To Modify Color Of PlotsRsquared Academy
 
Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language CHANDAN KUMAR
 
Data Visualization With R: Learn To Modify Font Of Graphical Parameters
Data Visualization With R: Learn To Modify Font Of Graphical ParametersData Visualization With R: Learn To Modify Font Of Graphical Parameters
Data Visualization With R: Learn To Modify Font Of Graphical ParametersRsquared Academy
 
Autocad commands
Autocad commandsAutocad commands
Autocad commandsAmit Kumar
 
Q plot tutorial
Q plot tutorialQ plot tutorial
Q plot tutorialAbhik Seal
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkTUOS-Sam
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphicsRafi_Dar
 
Creating a feature class
Creating a feature classCreating a feature class
Creating a feature classKU Leuven
 
Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using rTahera Shaikh
 
statistics Diagrams
 statistics Diagrams statistics Diagrams
statistics Diagramsanil sharma
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output PrimitivesRenita Santhmayora
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphicsetyca
 
Background This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docxBackground This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docxrosemaryralphs52525
 
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptxRamanathanSabesan
 
R and Visualization: A match made in Heaven
R and Visualization: A match made in HeavenR and Visualization: A match made in Heaven
R and Visualization: A match made in HeavenEdureka!
 
"contour.py" module
"contour.py" module"contour.py" module
"contour.py" moduleArulalan T
 
UNIT_4_data visualization.pptx
UNIT_4_data visualization.pptxUNIT_4_data visualization.pptx
UNIT_4_data visualization.pptxBhagyasriPatel2
 

Similar to R Data Visualization Tutorial: Bar Plots (20)

Data Visualization With R: Learn To Modify Color Of Plots
Data Visualization With R: Learn To Modify Color Of PlotsData Visualization With R: Learn To Modify Color Of Plots
Data Visualization With R: Learn To Modify Color Of Plots
 
Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
 
Data Visualization With R: Learn To Modify Font Of Graphical Parameters
Data Visualization With R: Learn To Modify Font Of Graphical ParametersData Visualization With R: Learn To Modify Font Of Graphical Parameters
Data Visualization With R: Learn To Modify Font Of Graphical Parameters
 
Autocad commands
Autocad commandsAutocad commands
Autocad commands
 
Lecture_3.pptx
Lecture_3.pptxLecture_3.pptx
Lecture_3.pptx
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Q plot tutorial
Q plot tutorialQ plot tutorial
Q plot tutorial
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
 
Creating a feature class
Creating a feature classCreating a feature class
Creating a feature class
 
Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using r
 
statistics Diagrams
 statistics Diagrams statistics Diagrams
statistics Diagrams
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output Primitives
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphics
 
Background This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docxBackground This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docx
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
 
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
 
R and Visualization: A match made in Heaven
R and Visualization: A match made in HeavenR and Visualization: A match made in Heaven
R and Visualization: A match made in Heaven
 
"contour.py" module
"contour.py" module"contour.py" module
"contour.py" module
 
UNIT_4_data visualization.pptx
UNIT_4_data visualization.pptxUNIT_4_data visualization.pptx
UNIT_4_data visualization.pptx
 

More from Rsquared Academy

Market Basket Analysis in R
Market Basket Analysis in RMarket Basket Analysis in R
Market Basket Analysis in RRsquared Academy
 
Practical Introduction to Web scraping using R
Practical Introduction to Web scraping using RPractical Introduction to Web scraping using R
Practical Introduction to Web scraping using RRsquared Academy
 
Writing Readable Code with Pipes
Writing Readable Code with PipesWriting Readable Code with Pipes
Writing Readable Code with PipesRsquared Academy
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRsquared Academy
 
Read/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into RRead/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into RRsquared Academy
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in RRsquared Academy
 
How to install & update R packages?
How to install & update R packages?How to install & update R packages?
How to install & update R packages?Rsquared Academy
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to VectorsRsquared Academy
 
Data Visualization With R: Learn To Combine Multiple Graphs
Data Visualization With R: Learn To Combine Multiple GraphsData Visualization With R: Learn To Combine Multiple Graphs
Data Visualization With R: Learn To Combine Multiple GraphsRsquared Academy
 
R Data Visualization: Learn To Add Text Annotations To Plots
R Data Visualization: Learn To Add Text Annotations To PlotsR Data Visualization: Learn To Add Text Annotations To Plots
R Data Visualization: Learn To Add Text Annotations To PlotsRsquared Academy
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RR Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RRsquared Academy
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RR Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RRsquared Academy
 
R Programming: Numeric Functions In R
R Programming: Numeric Functions In RR Programming: Numeric Functions In R
R Programming: Numeric Functions In RRsquared Academy
 

More from Rsquared Academy (20)

Handling Date & Time in R
Handling Date & Time in RHandling Date & Time in R
Handling Date & Time in R
 
Market Basket Analysis in R
Market Basket Analysis in RMarket Basket Analysis in R
Market Basket Analysis in R
 
Practical Introduction to Web scraping using R
Practical Introduction to Web scraping using RPractical Introduction to Web scraping using R
Practical Introduction to Web scraping using R
 
Joining Data with dplyr
Joining Data with dplyrJoining Data with dplyr
Joining Data with dplyr
 
Explore Data using dplyr
Explore Data using dplyrExplore Data using dplyr
Explore Data using dplyr
 
Data Wrangling with dplyr
Data Wrangling with dplyrData Wrangling with dplyr
Data Wrangling with dplyr
 
Writing Readable Code with Pipes
Writing Readable Code with PipesWriting Readable Code with Pipes
Writing Readable Code with Pipes
 
Introduction to tibbles
Introduction to tibblesIntroduction to tibbles
Introduction to tibbles
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
 
Read/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into RRead/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into R
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
 
How to install & update R packages?
How to install & update R packages?How to install & update R packages?
How to install & update R packages?
 
How to get help in R?
How to get help in R?How to get help in R?
How to get help in R?
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to Vectors
 
Data Visualization With R: Learn To Combine Multiple Graphs
Data Visualization With R: Learn To Combine Multiple GraphsData Visualization With R: Learn To Combine Multiple Graphs
Data Visualization With R: Learn To Combine Multiple Graphs
 
R Data Visualization: Learn To Add Text Annotations To Plots
R Data Visualization: Learn To Add Text Annotations To PlotsR Data Visualization: Learn To Add Text Annotations To Plots
R Data Visualization: Learn To Add Text Annotations To Plots
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RR Programming: Mathematical Functions In R
R Programming: Mathematical Functions In R
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RR Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In R
 
R Programming: Numeric Functions In R
R Programming: Numeric Functions In RR Programming: Numeric Functions In R
R Programming: Numeric Functions In R
 

Recently uploaded

Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Cathrine Wilhelmsen
 
Principles and Practices of Data Visualization
Principles and Practices of Data VisualizationPrinciples and Practices of Data Visualization
Principles and Practices of Data VisualizationKianJazayeri1
 
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBoston Institute of Analytics
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPTBoston Institute of Analytics
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksdeepakthakur548787
 
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...KarteekMane1
 
Networking Case Study prepared by teacher.pptx
Networking Case Study prepared by teacher.pptxNetworking Case Study prepared by teacher.pptx
Networking Case Study prepared by teacher.pptxHimangsuNath
 
INTRODUCTION TO Natural language processing
INTRODUCTION TO Natural language processingINTRODUCTION TO Natural language processing
INTRODUCTION TO Natural language processingsocarem879
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Boston Institute of Analytics
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsVICTOR MAESTRE RAMIREZ
 
Cyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded dataCyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded dataTecnoIncentive
 
What To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptxWhat To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptxSimranPal17
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesTimothy Spann
 
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxmodul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxaleedritatuxx
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our WorldEduminds Learning
 
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...Dr Arash Najmaei ( Phd., MBA, BSc)
 
The Power of Data-Driven Storytelling_ Unveiling the Layers of Insight.pptx
The Power of Data-Driven Storytelling_ Unveiling the Layers of Insight.pptxThe Power of Data-Driven Storytelling_ Unveiling the Layers of Insight.pptx
The Power of Data-Driven Storytelling_ Unveiling the Layers of Insight.pptxTasha Penwell
 

Recently uploaded (20)

Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)
 
Principles and Practices of Data Visualization
Principles and Practices of Data VisualizationPrinciples and Practices of Data Visualization
Principles and Practices of Data Visualization
 
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing works
 
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
 
Networking Case Study prepared by teacher.pptx
Networking Case Study prepared by teacher.pptxNetworking Case Study prepared by teacher.pptx
Networking Case Study prepared by teacher.pptx
 
Data Analysis Project: Stroke Prediction
Data Analysis Project: Stroke PredictionData Analysis Project: Stroke Prediction
Data Analysis Project: Stroke Prediction
 
INTRODUCTION TO Natural language processing
INTRODUCTION TO Natural language processingINTRODUCTION TO Natural language processing
INTRODUCTION TO Natural language processing
 
Insurance Churn Prediction Data Analysis Project
Insurance Churn Prediction Data Analysis ProjectInsurance Churn Prediction Data Analysis Project
Insurance Churn Prediction Data Analysis Project
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business Professionals
 
Cyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded dataCyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded data
 
What To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptxWhat To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptx
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
 
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxmodul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our World
 
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
 
The Power of Data-Driven Storytelling_ Unveiling the Layers of Insight.pptx
The Power of Data-Driven Storytelling_ Unveiling the Layers of Insight.pptxThe Power of Data-Driven Storytelling_ Unveiling the Layers of Insight.pptx
The Power of Data-Driven Storytelling_ Unveiling the Layers of Insight.pptx
 

R Data Visualization Tutorial: Bar Plots

  • 2. R2 AcademyCourse Material Slide 2 All the material related to this course are available on our website Scripts can be downloaded from GitHub Videos can be viewed on our Youtube Channel
  • 3. R2 AcademyTable Of Contents Slide 3 ➢ Objectives ➢ Introduction ➢ Simple bar plot ➢ Bar width ➢ Space between bars ➢ Bar Labels ➢ Horizontal Bars ➢ Density of shading lines ➢ Angle of shading lines ➢ Color ➢ Legend ➢ Border color ➢ Display/Hide vertical axes ➢ Display/Hide labels ➢ Modify font size of numeric (vertical Y) axis ➢ Modify font size of categorical(horizontal X) axis ➢ Line Type of horizontal axis ➢ Modify values of numeric (vertical Y) axis ➢ Summary
  • 4. R2 AcademyObjectives Slide 4 ➢ Create univariate bar plots ➢ Modify width, space and color of bars ➢ Add legend to the plot ➢ Modify appearance of the axis Note: In this tutorial, we use the Graphics package.
  • 5. R2 AcademyIntroduction Slide 5 A bar chart or bar graph is a chart that presents Grouped data with rectangular bars with lengths proportional to the values that they represent. The bars can be plotted vertically or horizontally. A vertical bar chart is sometimes called a column bar chart. - Wikipedia
  • 6. R2 AcademySimple Bar Plot Slide 6 In the Graphics package, the barplot function is used to create bar plots. You can learn more about this function from the help pages: help(barplot) To create a bar plot, we first tabulate the data using the table function and then use the tabulated data as the input. # basic bar plot data <- table(mtcars$cyl) barplot(data)
  • 7. R2 AcademyBar Width Slide 7 The width of the bars can be modified using the width option in the barplot function. In the below example, we specify the width of the middle bar to be twice that of the other two bars. # specify width of bars data <- table(mtcars$cyl) barplot(data, width = c(1, 2, 1))
  • 8. R2 AcademySpace Between Bars Slide 8 The space between the bars can be modified using the space option in the barplot function. In the below example, we specify the space between the bars to be 1.5 # specify space between bars data <- table(mtcars$cyl) barplot(data, space = 1.5)
  • 10. R2 AcademyLabels Slide 10 The labels of the bars can be modified using the names.arg option in the barplot function. The names must be specified using a character vector, the length of which should be equal to the number of bars. # specify labels for bars data <- table(mtcars$cyl) barplot(data, names.arg = c("Four", "Six", "Eight"))
  • 11. R2 AcademyHorizontal Bars Slide 11 Horizontal bar plots can be created using the horiz option in the barplot function. If it is set to TRUE, horizontal bars are drawn else vertical bars are drawn. Note: The default value of this option is FALSE. # horizontal bars data <- table(mtcars$cyl) barplot(data, horiz = TRUE)
  • 12. R2 AcademyShading Lines (Density) Slide 12 Shading lines can be drawn on the bars using the density option in the barplot function. It takes positive values and the density of the lines increases in proportion to the values specified. Note: The default value of this option is NULL. Lines will not be drawn if negative values are specified. # specify density of shading lines data <- table(mtcars$cyl) barplot(data, density = 10)
  • 14. R2 AcademyShading Lines (Angle) Slide 14 The angle of the shading lines drawn on the bars can be modified using the angle option in the barplot function. It takes both positive and negative values. # specify angle of shading lines data <- table(mtcars$cyl) barplot(data, density = 10, angle = 60)
  • 16. R2 AcademyColor Slide 16 The color of the bars can be modified using the col option in the barplot function. The color can be mentioned in RGB or hexadecimal format as well. # specify color of bars data <- table(mtcars$cyl) barplot(data, col = "blue")
  • 17. R2 AcademyColor Slide 17 Different colors for the bars can be created by specifying a character vector consisting of the names of the colors. If the number of colors mentioned is less than the number of bars, the colors will be repeated. # specify different color for bars data <- table(mtcars$cyl) barplot(data, col = c("red", "green", "blue"))
  • 18. R2 AcademyLegend Slide 18 A legend can be added using the legend.text option. If it is set to TRUE, a legend is added based on the values associated with the bars. We can also specify a character vector in which case the legend will be created on the basis of the input specified. We will explore legends in more detail in a separate tutorial. # specify legend data <- table(mtcars$cyl) barplot(data, col = c("red", "green", "blue"), legend.text = TRUE)
  • 19. R2 AcademyBorder Color Slide 19 The border color of the bars can be modified using the border option in the barplot function. The color can be mentioned in RGB or hexadecimal format as well. # specify border color of bars data <- table(mtcars$cyl) barplot(data, border = "blue")
  • 20. R2 AcademyBorder Color Slide 20 Different colors for the borders can be created by specifying a character vector consisting of the names of the colors. If the number of colors mentioned is less than the number of bars, the colors will be repeated. # specify different border color data <- table(mtcars$cyl) barplot(data, border = c("red", "green", "blue"))
  • 21. R2 AcademyTitle, Axis Labels & Range Slide 21 We can add a title and modify the axis labels and range using the options we learnt in the earlier tutorials. # specify title, axis labels and range data <- table(mtcars$cyl) barplot(data, col = c("red", "green", "blue"), main = "Frequency of Cylinders", xlab = "Number of Cylinders", ylab = "Frequency", ylim = c(0, 20))
  • 22. R2 AcademyAxes Slide 22 The vertical axes is not drawn if the axes option is set to FALSE. The default value is TRUE and hence a vertical axes is always drawn unless specified otherwise.
  • 23. R2 AcademyAxis Names Slide 23 The labels of the bars are not added if the axisnames option is set to FALSE. The default value is TRUE and hence the labels are always added unless specified otherwise.
  • 24. R2 AcademyNumeric Axis Font Size Slide 24 The font size of the numeric axis can be modified using the cex.axis option.
  • 25. R2 AcademyLabels Font Size Slide 25 The font size of the labels can be modified using the cex.names option.
  • 26. R2 AcademyAxis Line Type Slide 26 A line type for the horizontal axis can be specified using axis.lty option.
  • 27. R2 AcademyOffset Slide 27 The values of the numeric (vertical Y) axis can be modified using the offset option.
  • 28. R2 Academy Slide 28 ● Bar plots can be created using the barplot() function. ● Tabulate the data using the table() function before plotting. ● Modify the width of the bars using the width option. ● Modify the space between the bars using the space option. ● Modify the labels of the bars using the names.arg option. ● Create horizontal bars using the horiz option. ● Add shading lines using the density option and modify the angle of the lines using the angle option. ● Add color to the bars using the col and border options. ● Add legend to the plot using the legend.text option. ● Display/hide the numeric axis using the axes option. ● Display/hide the labels using the axis.names option. ● Modify font size of the numeric axis using the cex.axis option. ● Modify font size of the labels using the cex.names option. ● Modify line type of the horizontal axis using the axis.lty option. ● Modify values of the numeric axis using the offset option. Summary
  • 29. R2 AcademyNext Steps... Slide 29 In the next module: ✓ Bivariate Bar Plots ✓ Stacked Bar Plots ✓ Grouped Bar Plots
  • 30. R2 Academy Slide 30 Visit Rsquared Academy for tutorials on: → R Programming → Business Analytics → Data Visualization → Web Applications → Package Development → Git & GitHub