5_SingleVariableVisualization_2
5_SingleVariableVisualization_2
Keunwoo Kim
2019 Fall
Basic Function
A data vector and label information.
pie(c(3.5,1,4), labels=c("A","B","C"))
A
More Arguments
"col" and "main"
pie(c(3.5,1,4), labels=c("A","B","C"), col=c("red","blue","yellow"),
main="Pie Chart for A, B, and C")
Pie Chart for A, B, and C
pie(table(Store$country), col=rainbow(7))
CN
DE
BR
AU
GB US
JP
Basic Function
A data vector is used to draw a series of points.
vec = c(15, 12, 16, 18, 21, 17, 14, 13, 15, 11)
plot(vec)
20
18
vec
16
14
12
2 4 6 8 10
Index
"pch" Argument
Changes the type of points.
vec = c(15, 12, 16, 18, 21, 17, 14, 13, 15, 11)
plot(vec, pch=2) 20
18
vec
16
14
12
2 4 6 8 10
Index
More Arguments
Common arguments used for visualization.
vec = c(15, 12, 16, 18, 21, 17, 14, 13, 15, 11)
plot(vec, pch=20, main="Points", ylab="Values", col="blue")
Points
20
18
Values
16
14
12
2 4 6 8 10
Index
Basic Function
Use "plot" function with the argument type="l".
vec = c(15, 12, 16, 18, 21, 17, 14, 13, 15, 11)
plot(vec, type="l", main="Line Plot", ylab="Values", col="red")
Line Plot
20
18
Values
16
14
12
2 4 6 8 10
Index
vec = c(15, 12, 16, 18, 21, 17, 14, 13, 15, 11)
plot(vec, type="l", lwd=7, lty=2,
main="Line Plot", ylab="Values", col="red")
Line Plot
20
18
Values
16
14
12
2 4 6 8 10
Index
"lines" Function
"lines" function adds a line to an pre-existing plot.
150
100
50
0
0 10 20 30 40 50
Week Number
# adding legends
legend("topright", legend=c("Store101","Store102"),
lty=c(1,1), col=c("blue","red"), lwd=c(2,5))
Keunwoo Kim Single Variable Visualization 2 2019 Fall 12 / 20
Adding Legends
150
100
50
0
0 10 20 30 40 50
Week Number
Basic Function
A data vector and the names of bars.
A B C D
barplot(table(Store$country))
500
400
300
200
100
0
AU BR CN DE GB JP US
"aggregate" Function
The way to use is quite similar as for the "ftable" and "boxplot" functions.
## A B
## 1 0 1
## 2 1 19
## 3 2 4
Another Example
Average unit sales (product 1) for each country.
## country p1sales
## 1 AU 139.8462
## 2 BR 133.8269
## 3 CN 131.6394
## 4 DE 132.4538
## 5 GB 131.3654
## 6 JP 133.1274
## 7 US 133.7724
AU
BR
60000
CN
DE
GB
JP
50000
US
40000
30000
20000
10000
0
AU BR CN DE GB JP US
The purpose of this exercise is to complete the below table and visualize it.
1 Using aggregate and cbind functions, complete the below table.
2 Display four bar plots in one window, including (1) minimum, (2)
mean, (3) median, and (4) maximum price per carat information for
each of the four classes from the table.
Color Clarity Pr./Car. (Min) Pr./Car. (Mean) Pr./Car. (Med.) Pr./Car. (Max)
D IF ? ? ? ?
D Lower than IF ? ? ? ?
Lower than D IF ? ? ? ?
Lower than D Lower than IF ? ? ? ?