SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer joinNargis Ehsan
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaEdureka!
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Power bi notes
Power bi notesPower bi notes
Power bi notesanilkotha1
 
Html table tags
Html table tagsHtml table tags
Html table tagseShikshak
 
Tableau Dashboard Tutorial | Tableau Training For Beginners | Tableau Tutoria...
Tableau Dashboard Tutorial | Tableau Training For Beginners | Tableau Tutoria...Tableau Dashboard Tutorial | Tableau Training For Beginners | Tableau Tutoria...
Tableau Dashboard Tutorial | Tableau Training For Beginners | Tableau Tutoria...Edureka!
 
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...Edureka!
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2Raj vardhan
 
DAX and Power BI Training - 002 DAX Level 1 - 3
DAX and Power BI Training - 002 DAX Level 1 - 3DAX and Power BI Training - 002 DAX Level 1 - 3
DAX and Power BI Training - 002 DAX Level 1 - 3Will Harvey
 
Power BI Data Modeling.pdf
Power BI Data Modeling.pdfPower BI Data Modeling.pdf
Power BI Data Modeling.pdfVishnuGone
 
Python For Data Science Cheat Sheet
Python For Data Science Cheat SheetPython For Data Science Cheat Sheet
Python For Data Science Cheat SheetKarlijn Willems
 

La actualidad más candente (20)

SQL
SQL SQL
SQL
 
Subqueries
SubqueriesSubqueries
Subqueries
 
R code for data manipulation
R code for data manipulationR code for data manipulation
R code for data manipulation
 
Join sql
Join sqlJoin sql
Join sql
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer join
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
ALTERYX TOOL
ALTERYX TOOLALTERYX TOOL
ALTERYX TOOL
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Power bi notes
Power bi notesPower bi notes
Power bi notes
 
Context diagram
Context diagramContext diagram
Context diagram
 
Html table tags
Html table tagsHtml table tags
Html table tags
 
Tableau Dashboard Tutorial | Tableau Training For Beginners | Tableau Tutoria...
Tableau Dashboard Tutorial | Tableau Training For Beginners | Tableau Tutoria...Tableau Dashboard Tutorial | Tableau Training For Beginners | Tableau Tutoria...
Tableau Dashboard Tutorial | Tableau Training For Beginners | Tableau Tutoria...
 
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
 
Tableau Desktop Material
Tableau Desktop MaterialTableau Desktop Material
Tableau Desktop Material
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
Html
HtmlHtml
Html
 
DAX and Power BI Training - 002 DAX Level 1 - 3
DAX and Power BI Training - 002 DAX Level 1 - 3DAX and Power BI Training - 002 DAX Level 1 - 3
DAX and Power BI Training - 002 DAX Level 1 - 3
 
Power BI Data Modeling.pdf
Power BI Data Modeling.pdfPower BI Data Modeling.pdf
Power BI Data Modeling.pdf
 
Python For Data Science Cheat Sheet
Python For Data Science Cheat SheetPython For Data Science Cheat Sheet
Python For Data Science Cheat Sheet
 

Destacado

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
 

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

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

Más 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
 

Más 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
 

Último

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
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero 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
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
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
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
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
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一ffjhghh
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 

Último (20)

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
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero 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
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
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
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
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
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.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