RCourse-Lecture49-Statistics-Graphics - Scatter Plot and Bar Plots
RCourse-Lecture49-Statistics-Graphics - Scatter Plot and Bar Plots
Lecture 49
Graphics
:::
Scatter Plot and Bar Plots
Shalabh
Department of Mathematics and Statistics
Indian Institute of Technology Kanpur
1
Graphics:
Graphics summarize the information contained in a data.
5
Scatter Plot
Example
Height of 50 persons are recorded in centimeters as follows:
166,125,130,142,147,159,159,147,165,156,149,164,137,166,135,142,
133,136,127,143,165,121,142,148,158,146,154,157,124,125,158,159,
164,143,154,152,141,164,131,152,152,161,143,143,139,131,125,145,
140,163
> height = c(166,125,130,142,147,159,159,147,
165,156,149,164,137,166,135,142,133,136,127,143,
165,121,142,148,158,146,154,157,124,125,158,159,
164,143,154,152,141,164,131,152,152,161,143,143,
139,131,125,145,140,163)
6
Scatter Plot
Example
plot(height)
7
Scatter Plot
Example
plot(height, col = "red")
8
Bar plots:
Visualize the relative or absolute frequencies of observed values
of a variable.
9
Bar plots:
Visualize the relative or absolute frequencies of observed values
of a variable.
barplot(table(x)/length(x))
10
Bar plots:
> help("barplot")
11
Bar plots:
Example:
Code the 10 persons by using, say 1 for male (M) and 2 for female (F).
M, F, M, F, M, M, M, F, M, M
1, 2, 1, 2, 1, 1, 1, 2, 1, 1
12
Bar plots:
Example:
> barplot(gender)
13
Bar plots:
Example:
> table(gender)
gender
1 2
7 3
> barplot(table(gender))
14
Bar plots:
Example:
> table(gender)/length(gender)
gender
1 2
0.7 0.3
> barplot(table(gender)/length(gender))
15
Bar plots:
Example:
Consider the following data on pizza home delivery. There are three
branches (East ‐ coded as 1, West ‐ coded as 2, Central ‐ coded as 3)
of the restaurant.
The 100 values from code Directions are as follows:
direction =
c(1,1,2,1,2,3,2,2,3,3,3,1,2,3,2,2,3,1,1,3,3,1,2
,1,3,3,3,2,2,2,2,1,2,2,1,1,1,3,2,2,1,2,3,2,2,1,
2,3,3,2,1,2,2,3,1,1,2,1,2,3,2,3,2,2,3,1,2,3,3,3
,2,1,1,1,2,1,1,2,1,2,3,3,1,2,3,3,2,1,2,3,2,1,3,
2,2,2,2,3,2,2)
16
Bar plots:
Example:
barplot(direction)
17
Bar plots:
Example
barplot(table(direction))
18
Bar plots:
Example
barplot(table(direction)/length(direction))
19
Bar plots:
Example: Adding colours
barplot(table(direction), col=c("red", "green",
"blue") )
20
Bar plots:
Example: Adding title
barplot(table(direction), col=c("red", "green",
"blue"), main="Directions of food delivery" )
21
Bar plots:
Example: Adding legends
barplot(table(direction), col=c("red", "green",
"blue"), main="Directions of food delivery",
legend.text=c("dir1", "dir2", "dir3") )
22
Bar plots:
Example: Adding Subtitle
barplot(table(direction), col=c("red", "green",
"blue"), main="Directions of food delivery",
legend.text=c("dir1", "dir2", "dir3"),
sub="Three directions" )
23
Bar plots:
Example: Adding Subtitle
barplot(table(direction), col=c("red", "green",
"blue"), main="Directions of food delivery",
legend.text=c("dir1", "dir2", "dir3"),
sub="Three directions", xlab="Food Delivery
Directions", ylab="Number of Deliveries" )
24