Graphics activity
Problems
Student activities
The table shows the favorite activities of 200 students. What type of graph would be most appropriate to show the data as parts of a whole?
| Favorite Activity | Percent of Students |
|---|---|
| Watching TV | 23% |
| Playing Games | 30% |
| Browsing the Internet | 15% |
| Gardening | 17% |
| Shopping | 15% |
activity = c("Watching TV" = 23, "Playing Games" = 30,
"Browsing\nthe Internet" = 15, "Garding" = 17,
"Shopping" = 15)
labels = paste0(activity,"%")
pie(activity, labels, col = hcl.colors(5, alpha = 0.8),
main = "Activities of 200 students")
legend("right", legend = names(activity), cex = 0.8,
fill = hcl.colors(5, alpha = 0.8))Money spent on military
Identify the graph that is most appropriate to represent a data that denotes the amount of money spent on military over a period of time.
A line plot.
set.seed(2)
money = sort(sample(seq(1,10,0.1),23))
year = 2000:2022
plot(year, money, type = "l", lwd = 2, xlab = "Year",
ylab = "Millons of dollars",
main = "Money spent on military")
points(year, money, pch = 21, col = 1, bg = 4, cex = 1.5, lwd = 2)Time spent to get work
Which graph would be most appropriate to show the time in number of minutes that 25 employees take to travel to the office?
A stem because of the small number of sample.
set.seed(2)
time = round(rnorm(25,25,5))
stem(time, scale = 1)##
## The decimal point is 1 digit(s) to the right of the |
##
## 1 | 3
## 1 | 99
## 2 | 01344
## 2 | 555667799
## 3 | 00334
## 3 | 555
Length of names
A survey was conducted on the length of the names of the students in a class. What type of graph would be most appropriate to show the range of the data?
It depends of the number of students and the range of the data.
set.seed(47)
lengths = sample(3:15, 50, TRUE, dnorm(3:15, 6, 2))
barplot(table(lengths), density = 25, col = "#E9AE6D",
xlab = "Length", main = "Length of names")Most common pets
The table shows the kinds of pets the students have in a class. What type of graph would be most appropriate for the data?
| Pet | Frequency of the Pet |
|---|---|
| Birds | 18 |
| Cats | 5 |
| Dogs | 23 |
| Fish | 17 |
| Rabbits | 6 |
| Horse | 4 |
pet = c("Birds","Cats","Dogs","Fish","Rabbits","Horse")
count = c(18,5,23,17,6,4)
barplot(count, names.arg = pet, xlab = "Kind of pets",
ylab = "Frequency", col = "#6DA8E9")Yearly average earnings
The table shows the yearly average earnings (in thousands of dollars) for men and women. Which type of graph would be most appropriate for the data?
| Year | 1998 | 1999 | 2000 | 2001 |
|---|---|---|---|---|
| Men | 28.9 | 29.3 | 29.6 | 30.2 |
| Women | 19.5 | 20.4 | 22.3 | 22.4 |
year = 1998:2001
men = c(28.9,29.3,29.6,30.2)
women = c(19.5,20.4,22.3,22.4)
plot(year, men, type = "o", ylim = c(18,32),
main = "Yearly average earnings", ylab = "Thousands of dollars",
xaxt = "n", col = 3, pch = 19, cex = 1.5, lwd = 2)
lines(year, women, type = "o", col = 2, pch = 19, cex = 1.5, lwd = 2)
axis(1, year)
legend("bottomright", horiz = T, legend = c("Men","Women"),
pch = 19, col = 3:2, lty = 1, cex = 0.8, bty = "n")Weights
The weight of 15 people(in kg) are listed: 34, 49, 23, 54, 35, 64, 40, 53, 52, 76, 48, 21, 47, 34, and 33. Which type of graph is appropriate for the data?
weights = c(34,49,23,54,35,64,40,53,52,76,48,21,47,34,33)
stem(weights, scale = 2)##
## The decimal point is 1 digit(s) to the right of the |
##
## 2 | 13
## 3 | 3445
## 4 | 0789
## 5 | 234
## 6 | 4
## 7 | 6
School enrollment
The table shows the school enrollment between 1992 to 1996. Which type of graph is appropriate for the data?
| Year | Number of students |
|---|---|
| 1992 | 65 |
| 1993 | 85 |
| 1994 | 70 |
| 1995 | 70 |
| 1996 | 75 |
par(mfrow = c(1,2))
year = 1992:1996
students = c(65,85,70,70,75)
plot(year, students, type = "o", ylab = "Number fo students",
xlab = "Year", main = "School enrollment", pch = 19, col = 2)
barplot(students, names.arg = year, ylab = "Number of students",
xlab = "Year", main = "School enrollment", col = 2)Cars sold by color
The table shows the number of cars sold in a week. Which type of graph is appropriate for the data?
| Color of car | Red | White | Orange | Blue |
|---|---|---|---|---|
| Number of cars | 15 | 24 | 7 | 11 |
par(mfrow = c(1,2))
cars = c(15,24,7,11)
names(cars) = c("Red","White","Orange","Blue")
colors = c("#E91313","#FFFFFF","#ED7F11","#0E65C4")
pie(cars, labels = paste0(round(cars/sum(cars)*100,1),"%"),
col = colors, main = "Cars sold in a week by color")
barplot(sort(cars, decreasing = TRUE), density = 20,
main = "Cars sold in a week by color", ylim = c(0,25))School days during school year
The table shows the number of school days each month during the last school year.
| Month | Aug | Sep | Oct | Nov | Dec | Jan | Feb | Mar | Apr |
|---|---|---|---|---|---|---|---|---|---|
| Number of Days | 4 | 18 | 20 | 15 | 12 | 14 | 19 | 14 | 21 |
months = month.abb[c(8:12,1:4)]
days = c(4,18,20,15,12,14,19,14,21)
barplot(days, names.arg = months,
xlab = "Month of last school year",
ylab = "Number of school days", col = "#7CDDC8")Which best describe?
Which of the graphs best represents the data?
Graph 2 better describes the data.