SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Linear regression
Linear regression Linear regression
Linear regression mohamed Naas
 
Principal Component Analysis and Clustering
Principal Component Analysis and ClusteringPrincipal Component Analysis and Clustering
Principal Component Analysis and ClusteringUsha Vijay
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Guy Lebanon
 
DIAGNÓSTICO DE LP E MAT- 4ºANO- 2023.pdf
DIAGNÓSTICO DE LP E MAT- 4ºANO- 2023.pdfDIAGNÓSTICO DE LP E MAT- 4ºANO- 2023.pdf
DIAGNÓSTICO DE LP E MAT- 4ºANO- 2023.pdfValdemirMaia4
 
computer graphics
computer graphicscomputer graphics
computer graphicsMegabi Mamo
 
Computer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and GradientComputer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and GradientAhmed Gad
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph AJAL A J
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABAli Ghanbarzadeh
 
Logistic regression
Logistic regressionLogistic regression
Logistic regressionVARUN KUMAR
 
Hough Transform By Md.Nazmul Islam
Hough Transform By Md.Nazmul IslamHough Transform By Md.Nazmul Islam
Hough Transform By Md.Nazmul IslamNazmul Islam
 

Tendances (20)

Linear regression
Linear regression Linear regression
Linear regression
 
Principal Component Analysis and Clustering
Principal Component Analysis and ClusteringPrincipal Component Analysis and Clustering
Principal Component Analysis and Clustering
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
Unit 5 Quantization
Unit 5 QuantizationUnit 5 Quantization
Unit 5 Quantization
 
Regression
RegressionRegression
Regression
 
Logistical Regression.pptx
Logistical Regression.pptxLogistical Regression.pptx
Logistical Regression.pptx
 
Project ppt
Project pptProject ppt
Project ppt
 
DIAGNÓSTICO DE LP E MAT- 4ºANO- 2023.pdf
DIAGNÓSTICO DE LP E MAT- 4ºANO- 2023.pdfDIAGNÓSTICO DE LP E MAT- 4ºANO- 2023.pdf
DIAGNÓSTICO DE LP E MAT- 4ºANO- 2023.pdf
 
Random Variable
Random VariableRandom Variable
Random Variable
 
computer graphics
computer graphicscomputer graphics
computer graphics
 
Lda
LdaLda
Lda
 
Computer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and GradientComputer Vision: Correlation, Convolution, and Gradient
Computer Vision: Correlation, Convolution, and Gradient
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph
 
Linear Regression.pptx
Linear Regression.pptxLinear Regression.pptx
Linear Regression.pptx
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
 
06 Vector Visualization
06 Vector Visualization06 Vector Visualization
06 Vector Visualization
 
Logistic regression
Logistic regressionLogistic regression
Logistic regression
 
Simple Linear Regression
Simple Linear RegressionSimple Linear Regression
Simple Linear Regression
 
Hough Transform By Md.Nazmul Islam
Hough Transform By Md.Nazmul IslamHough Transform By Md.Nazmul Islam
Hough Transform By Md.Nazmul Islam
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

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
 
Decision Making Under Uncertainty - Is It Better Off Joining a Partnership or...
Decision Making Under Uncertainty - Is It Better Off Joining a Partnership or...Decision Making Under Uncertainty - Is It Better Off Joining a Partnership or...
Decision Making Under Uncertainty - Is It Better Off Joining a Partnership or...ThinkInnovation
 
Digital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfDigital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfNicoChristianSunaryo
 
Statistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfStatistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfnikeshsingh56
 
Role of Consumer Insights in business transformation
Role of Consumer Insights in business transformationRole of Consumer Insights in business transformation
Role of Consumer Insights in business transformationAnnie Melnic
 
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)
 
DATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etcDATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etclalithasri22
 
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelDecoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelBoston Institute of Analytics
 
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
 
Presentation of project of business person who are success
Presentation of project of business person who are successPresentation of project of business person who are success
Presentation of project of business person who are successPratikSingh115843
 
IBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaIBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaManalVerma4
 
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...Jack Cole
 
Predictive Analysis - Using Insight-informed Data to Plan Inventory in Next 6...
Predictive Analysis - Using Insight-informed Data to Plan Inventory in Next 6...Predictive Analysis - Using Insight-informed Data to Plan Inventory in Next 6...
Predictive Analysis - Using Insight-informed Data to Plan Inventory in Next 6...ThinkInnovation
 

Dernier (16)

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...
 
Decision Making Under Uncertainty - Is It Better Off Joining a Partnership or...
Decision Making Under Uncertainty - Is It Better Off Joining a Partnership or...Decision Making Under Uncertainty - Is It Better Off Joining a Partnership or...
Decision Making Under Uncertainty - Is It Better Off Joining a Partnership or...
 
Digital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfDigital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdf
 
Statistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfStatistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdf
 
Role of Consumer Insights in business transformation
Role of Consumer Insights in business transformationRole of Consumer Insights in business transformation
Role of Consumer Insights in business transformation
 
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...
 
DATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etcDATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etc
 
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelDecoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
 
2023 Survey Shows Dip in High School E-Cigarette Use
2023 Survey Shows Dip in High School E-Cigarette Use2023 Survey Shows Dip in High School E-Cigarette Use
2023 Survey Shows Dip in High School E-Cigarette Use
 
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
 
Presentation of project of business person who are success
Presentation of project of business person who are successPresentation of project of business person who are success
Presentation of project of business person who are success
 
IBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaIBEF report on the Insurance market in India
IBEF report on the Insurance market in India
 
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
 
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: Stroke Prediction
Data Analysis Project: Stroke PredictionData Analysis Project: Stroke Prediction
Data Analysis Project: Stroke Prediction
 
Predictive Analysis - Using Insight-informed Data to Plan Inventory in Next 6...
Predictive Analysis - Using Insight-informed Data to Plan Inventory in Next 6...Predictive Analysis - Using Insight-informed Data to Plan Inventory in Next 6...
Predictive Analysis - Using Insight-informed Data to Plan Inventory in Next 6...
 

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