SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Application of integral calculus
Application of integral calculusApplication of integral calculus
Application of integral calculus
 
Lesson 18: Maximum and Minimum Values (slides)
Lesson 18: Maximum and Minimum Values (slides)Lesson 18: Maximum and Minimum Values (slides)
Lesson 18: Maximum and Minimum Values (slides)
 
Data Visualization With R
Data Visualization With RData Visualization With R
Data Visualization With R
 
Q-Q Plot | Statistics
Q-Q Plot | StatisticsQ-Q Plot | Statistics
Q-Q Plot | Statistics
 
Python for R Users
Python for R UsersPython for R Users
Python for R Users
 
Taylor series
Taylor seriesTaylor series
Taylor series
 
Reading Data into R
Reading Data into RReading Data into R
Reading Data into R
 
Graphics in R
Graphics in RGraphics in R
Graphics in R
 
Class ppt intro to r
Class ppt intro to rClass ppt intro to r
Class ppt intro to r
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Introduction to regression
Introduction to regressionIntroduction to regression
Introduction to regression
 
Functions in mathematics
Functions in mathematicsFunctions in mathematics
Functions in mathematics
 
Use of integral calculus in engineering
Use of integral calculus in engineeringUse of integral calculus in engineering
Use of integral calculus in engineering
 
Getting Started with R
Getting Started with RGetting Started with R
Getting Started with R
 
Linear regression
Linear regressionLinear regression
Linear regression
 
Graph theory
Graph theory Graph theory
Graph theory
 
Quantitative Data Analysis using R
Quantitative Data Analysis using RQuantitative Data Analysis using R
Quantitative Data Analysis using R
 
Gaussian Elimination Method
Gaussian Elimination MethodGaussian Elimination Method
Gaussian Elimination Method
 
Regression analysis
Regression analysisRegression analysis
Regression analysis
 

Andere mochten auch

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
 

Andere mochten auch (9)

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

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramMoniSankarHazra
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxolyaivanovalion
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 

Kürzlich hochgeladen (20)

Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 

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