ST 308 QUIZ 3 QUESTIONS WITH VERIFIED ANSWERS
4 types of graphical summaries (across subgroups) - Answers - 1. bar plots (categorical
data)
2. histograms
3. box plots
4. scatter plots
3 major systems for plotting - Answers - 1. base r (built-in functions)
2. lattice
3. ggplot2 (sort of part of the tidyverse)
lattice - Answers - great for doing multiple plots (not part of tidyverse)
which major system for plotting will we be using - Answers - ggplot2
what ggplot2 code will create a plot instance - Answers - ggplot(data = data_frame)
what functions of ggplot2 will add layers (visualization) to the plot - Answers - geom or
stat
which function in ggplot2 allows us to modify layer "mapping" args - Answers - aes()
what does it mean to modify layers - Answers - to map variables to attributes of the plot
ex:
size, color, x variable, y variable
how do you create a ggplot2 barplot - Answers - ggplot() + geom_bar()
how do you specify the categories that go across the x axis in a bar plot - Answers -
aes(x = ...)
ex:
ggplot(data = titanicData, aes(x = survived))
what must you add to the bar plot? - Answers - either geom or stat layer
ex:
ggplot(data = titanicData, aes(x = survived) + geom_bar)
general instructions for making ggplot2 bar plot - Answers - 1 - save base object with
global aes() assignments
, 2 - add layers
what does the ggplot function itself create? - Answers - a base plotting object with
global aesthetics
What symbol is used to add another layer to a ggplot object? - Answers - +
What geom layer below would be used in creating a bar plot? - Answers - geom_bar()
factor - Answers - special class of vector with a levels attribute
levels - Answers - define all possible values for that variable
ex:
define possible values 1-7 for a variable like Day which goes from monday through
sunday
- prevents r from thinking that a categorical variable is numerical
why are factors great for plotting - Answers - 1. you can order the levels and give nicer
labels
example of creating a new factor version of the "survived" variable - Answers -
titanicData <- titanicData%>%
mutate(mySurvived = as.factor(survived))
str(titanicData$mySurvived)
- "survived" has 2 levels; "0" (died) or "1"(survived).
example of creating better labels for the 2 levels of "survived" variable - Answers -
levels(titanicData$mySurvived) <- c("Died", "Survived")
levels(titanicData$mySurvived)
- turns "0" into "Died" and "1" into "Survived"
example of changing the ordering for the 2 levels of "survived" variable - Answers -
titanicData <- titanicData%>%
mutate(mySurvived = factor(mySurvived, levels = c("Survived", "Died")))
table(titanicData$mySurvived)
- puts "survived" on the left of "died", instead of the opposite original composition
2 ways to prepare our data - Answers - 1. convert another categorical variable to a
factor for better plotting
2. drop any rows with missing values for any of these variables
4 types of graphical summaries (across subgroups) - Answers - 1. bar plots (categorical
data)
2. histograms
3. box plots
4. scatter plots
3 major systems for plotting - Answers - 1. base r (built-in functions)
2. lattice
3. ggplot2 (sort of part of the tidyverse)
lattice - Answers - great for doing multiple plots (not part of tidyverse)
which major system for plotting will we be using - Answers - ggplot2
what ggplot2 code will create a plot instance - Answers - ggplot(data = data_frame)
what functions of ggplot2 will add layers (visualization) to the plot - Answers - geom or
stat
which function in ggplot2 allows us to modify layer "mapping" args - Answers - aes()
what does it mean to modify layers - Answers - to map variables to attributes of the plot
ex:
size, color, x variable, y variable
how do you create a ggplot2 barplot - Answers - ggplot() + geom_bar()
how do you specify the categories that go across the x axis in a bar plot - Answers -
aes(x = ...)
ex:
ggplot(data = titanicData, aes(x = survived))
what must you add to the bar plot? - Answers - either geom or stat layer
ex:
ggplot(data = titanicData, aes(x = survived) + geom_bar)
general instructions for making ggplot2 bar plot - Answers - 1 - save base object with
global aes() assignments
, 2 - add layers
what does the ggplot function itself create? - Answers - a base plotting object with
global aesthetics
What symbol is used to add another layer to a ggplot object? - Answers - +
What geom layer below would be used in creating a bar plot? - Answers - geom_bar()
factor - Answers - special class of vector with a levels attribute
levels - Answers - define all possible values for that variable
ex:
define possible values 1-7 for a variable like Day which goes from monday through
sunday
- prevents r from thinking that a categorical variable is numerical
why are factors great for plotting - Answers - 1. you can order the levels and give nicer
labels
example of creating a new factor version of the "survived" variable - Answers -
titanicData <- titanicData%>%
mutate(mySurvived = as.factor(survived))
str(titanicData$mySurvived)
- "survived" has 2 levels; "0" (died) or "1"(survived).
example of creating better labels for the 2 levels of "survived" variable - Answers -
levels(titanicData$mySurvived) <- c("Died", "Survived")
levels(titanicData$mySurvived)
- turns "0" into "Died" and "1" into "Survived"
example of changing the ordering for the 2 levels of "survived" variable - Answers -
titanicData <- titanicData%>%
mutate(mySurvived = factor(mySurvived, levels = c("Survived", "Died")))
table(titanicData$mySurvived)
- puts "survived" on the left of "died", instead of the opposite original composition
2 ways to prepare our data - Answers - 1. convert another categorical variable to a
factor for better plotting
2. drop any rows with missing values for any of these variables