Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 20

Data Visualization

Mahesh Matha
Assistant Professor
mpm001@chowgules.ac.in
• Bar Graphs
Bar Graphs

A bar graph is a graphical display of data using bars of different heights.

Problem 1: Suppose a survey of your friends was done to determine the


type of movie that they like.
Comedy 4
Action 5
Romance 6
Drama 1
SciFi 4
Display the data using a bar graph.
Bar Graphs

barplot(height, names.arg = NULL, xlab = NULL, ylab = NULL, col=NULL,


main=NULL, border=NULL).

.
Bar Graphs

Problem 2 145 people were asked the question: Which is their favourite
fruit? The answers are given below. Generate the bar graph.

Fruit No of people
Apple 35
Orange 30
Banana 10
KiwiFruit 25
Blueberry 40
Grapes 5
Bar Graphs
Horizontal Bar Graphs

• Make the necessary changes for x and y axis and in barplot function set
argument “horiz” to true.
•Repeat problems 1 & 2 to draw an horizontal bar graph.
•Problem 2 Solution
Horizontal Bar Graphs

• Problem 1 Solution
Stacked Bar Graph

•It is a bar graph that is used to break down and compare parts of a whole.

•Different colours are used to illustrate the different categories in the bar.

•Problem 1: The following data is given. Depict it in a stacked bar graph.

Instrument No of Boys Girls


Students
Drum 3 2 1
Trombone 8 5 3
Trumpet 7 3 4
Tuba 2 1 1
Stacked Bar Graph

• The legend() function is used to specify the legend.

• It has many arguments. We consider 4 of them

• First: Legend’s position: left, right, center, top, topleft, topright, bottom,
bottomleft, bottomright.

• Second: Vector containing the text of the legend.

• Third: cex=1.5. The character expansion factor. It is a numeric value


giving the amount by which plotting text and symbols must be
magnified relative to the default.

• Fourth: fill. The colours in the legend


Stacked Bar Graph

•It is a bar graph that is used to break down and compare parts of a whole.
The Stacked Bar graph

Problem 2. The following data set is give below. Draw a stacked bar graph.

Q1Actual Q2Actual Q1Budget Q2Budget


Coffee 1900 2200 2000 2000
Tea 1600 1650 1500 1500
Milk 1000 950 1200 1200
The Stacked Bar graph
Grouped Bar Graph

•In a Grouped Bar Graph, for each categorical group, there are 2 or more
bars.

•These bars are colour-coded to represent a particular grouping.

•In the barplot() method, beside is a logical value.

•If FALSE, the columns of the height are portrayed as stacked bars and if
TRUE the columns are portrayed as juxtaposed bars.
Grouped Bar Graph
Grouped Bar Graph


Summary
 A bar graph is a graphical display of data using bars of different heights.

 A Stacked Bar Graph is a bar graph that is used to break down and compare
parts of a whole. Different colours are used to illustrate the different
categories in the bar.

 In a Grouped Bar Graph, for each categorical group, there are 2 or more
bars. These bars are colour-coded to represent a particular grouping.
Questions
1) What is a bar graph?

2) What is meant by a stacked bar graph?

3) Explain the Grouped Bar Graph.


References

• https://www.tutorialspoint.com/r/index.htm
Thank You
Mahesh Matha
Assistant Professor
mpm001@chowgules.ac.in

You might also like