Data Visualization with R
- 52Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What does the “grammar of graphics” refer to in ggplot2, and what does ggplot2 use it to create?
52 questions
- 1
What does the “grammar of graphics” refer to in ggplot2, and what does ggplot2 use it to create?
Model answer
It is a framework for constructing visualizations from defined components. ggplot2 uses it to create graphics, including high-quality graphics suitable for print.
Explanation
The tutorial describes ggplot2 as a visualization tool built around the grammar of graphics and emphasizes its ability to produce print-quality output.
- 2
Name the six components of the ggplot2 grammar described in the tutorial.
Model answer
The six components are data, layers, scales, coordinates, faceting, and themes.
Explanation
Each component contributes data or a different aspect of how the visualization is represented and displayed.
- 3
What role does data play in a ggplot2 visualization?
Model answer
Data is the raw material from which the visualization is constructed; without data, there is no visualization.
Explanation
The tutorial identifies data as the starting material for a plot.
- 4
What are layers in a ggplot2 visualization?
Model answer
Layers are the visible graphical elements, such as points, lines, or bars, that appear in the plot.
Explanation
Layers determine what graphical marks the viewer sees.
- 5
Why does a visualization need scales?
Model answer
Scales map data values to the graphical output so they fit appropriately within the available plotting space.
Explanation
A plot has limited screen space, so scales translate data values into usable visual dimensions or properties.
- 6
What do coordinates determine in a ggplot2 plot, and which coordinate system is used most often by default?
Model answer
Coordinates determine the plot’s visual perspective. The default and most commonly used system is a two-dimensional x-y grid.
Explanation
Bar charts, line charts, and histograms commonly use this grid, though ggplot2 supports other coordinate systems.
- 7
What is faceting used for in ggplot2?
Model answer
Faceting divides a visualization into panels based on one or more variables, allowing visual drill-down into subsets of the data.
Explanation
Each panel displays the data for a selected category or combination of categories.
- 8
What can themes control in a ggplot2 visualization?
Model answer
Themes control display details such as fonts, font sizes, colors, and the overall look and feel of the plot.
Explanation
Themes provide fine-grained control over the presentation of a graphic.
- 9
What three elements are generally needed to create a basic ggplot2 visualization?
Model answer
A basic plot needs data, an aesthetic mapping, and a layer specifying what to draw.
Explanation
The tutorial presents these as the practical essentials for getting a graphic started; many other settings have useful defaults.
- 10
What is an aesthetic mapping in ggplot2?
Model answer
It specifies how variables in the data map to visual properties, such as assigning a variable to the x-axis or to a fill color.
Explanation
Aesthetic mappings tell ggplot2 how the selected data should be represented in the plot.
- 11
What do ggplot2 functions beginning with
geom_specify?Model answer
They specify the type of graphical layer or visualization to draw, such as a bar chart, histogram, or density plot.
Explanation
The tutorial identifies
geom_functions as the functions that define the plot’s graphical form. - 12
Why can someone make useful ggplot2 plots without mastering every grammar component?
Model answer
ggplot2 provides defaults that work well in many cases, so detailed control is mainly needed when customizing a graphic.
Explanation
The tutorial distinguishes the full customization available from the smaller set of features needed for many common plots.
- 13
Why was the Titanic dataset chosen for the tutorial’s analysis?
Model answer
The Titanic story is familiar to a broad audience, and the dataset resembles business data in its imperfect, sometimes overloaded fields.
Explanation
Familiarity helps a diverse audience follow the example, while the data’s characteristics make it a useful proxy for real-world customer profile data.
- 14
How is the Titanic dataset used as a proxy for business data?
Model answer
Its customer-like profile variables, imperfect data, and fields with overloaded meanings resemble characteristics often found in business systems.
Explanation
The tutorial gives customer churn analysis as an example of a business problem that might use comparable profile data.
- 15
What does the
survivedvariable represent, and how are its values interpreted?Model answer
It is a binary indicator: 0 means the passenger perished, and 1 means the passenger survived.
Explanation
Although it is stored as numeric values, it represents two categories rather than a quantity for arithmetic operations.
- 16
What does
pclassrepresent, and why should it be treated as categorical rather than ratio-scale numeric data?Model answer
It represents first-, second-, or third-class ticket accommodations. The class numbers are labels, so a class of 3 is not three times a class of 1.
Explanation
The tutorial argues that multiplication or division of these class codes has no meaningful interpretation.
- 17
What values does the
sexvariable contain, and how should it be treated for plotting?Model answer
It contains male and female values and should be treated as a categorical variable, or factor.
Explanation
The values identify categories rather than measurable numeric quantities.
- 18
How is
agecharacterized in the dataset?Model answer
Age is a continuous numeric variable and can include decimal values.
Explanation
The tutorial gives ages such as 33.44 years as examples of its numeric representation.
- 19
What does
sibspcount, and why is its meaning described as overloaded?Model answer
It records the number of siblings and/or a spouse traveling with a passenger. Its meaning is overloaded because the field can represent siblings, a spouse, or both.
Explanation
The same field combines multiple related relationship categories rather than distinguishing them in separate columns.
- 20
What does
parchcount, and why is its meaning described as overloaded?Model answer
It records the number of parents and/or children traveling with a passenger. Its meaning is overloaded because it combines these relationship categories in one field.
Explanation
The column does not separately identify counts of parents and counts of children.
- 21
What information do
ticket,fare, andcabinprovide?Model answer
ticketgives the ticket’s serial number,faregives the amount paid in pounds sterling, andcabinrecords an assigned cabin number when one was available.Explanation
These variables describe a passenger’s ticket, its cost, and cabin assignment information.
- 22
What does the embarkation variable record, and what do its codes mean?
Model answer
It records the port where a passenger boarded: C for Cherbourg, Q for Queenstown, and S for Southampton.
Explanation
The codes represent three distinct embarkation ports and are therefore categorical values.
- 23
Why were passenger ID and name ignored in the tutorial’s main analysis?
Model answer
Passenger ID is unique to each row, and each passenger has a unique name, so neither provides useful signal in its existing form for the analysis.
Explanation
The tutorial notes that text analysis could potentially extract information from names, but that was outside the presentation’s scope.
- 24
How large was the Titanic dataset used in the demonstration, and what data-quality issue was noted for age?
Model answer
It contained 891 observations and 12 columns, and the age column had 177 missing values.
Explanation
The missing ages mattered because plots involving age would need to account for incomplete observations.
- 25
Why should
survived,pclass,sex, and embarkation be represented as factors in R?Model answer
They represent categories rather than quantities for meaningful arithmetic, so treating them as factors makes their categorical nature explicit to R and ggplot2.
Explanation
Categorical factors can also be used in aesthetic mappings, such as color-coding plot elements.
- 26
Why is a bar chart appropriate for displaying counts of a categorical variable such as survival status?
Model answer
A bar chart displays the count in each category, which is a meaningful summary for categorical data when arithmetic on category codes is not.
Explanation
The tutorial uses bars to compare the number of passengers in each survival category.
- 27
What broad conclusion did the overall survival chart show about Titanic passengers?
Model answer
More passengers perished than survived; the tutorial estimated that about 62% perished and 38% survived.
Explanation
The bar chart showed the relative counts, and a proportion table provided the approximate percentages.
- 28
How can a ggplot2 bar chart show survival outcomes separately for male and female passengers?
Model answer
Map
sexto the x-axis and mapsurvivedto the bar fill, so the bars are divided and color-coded by survival outcome.Explanation
The fill mapping makes the survival counts visible within each sex category.
- 29
What did the survival-by-sex visualization indicate about survival and passenger counts?
Model answer
Females survived disproportionately more often than males, and there were approximately twice as many male passengers as female passengers.
Explanation
The color-coded bars showed both the survival outcomes within each sex and the relative totals of male and female passengers.
- 30
What pattern did the survival-by-ticket-class chart show?
Model answer
Survival declined from first class to third class: more than half of first-class passengers survived, second class was about half, and third class was about one quarter.
Explanation
The bars suggested that ticket class was associated with survival, though the chart alone does not establish why.
- 31
How can fill color help make a categorical bar chart more informative?
Model answer
Mapping a categorical variable such as survival to fill color distinguishes outcomes within each bar, making their relative counts easier to compare.
Explanation
The tutorial uses separate colors for passengers who perished and those who survived.
- 32
How can a plot’s axis label and title be changed in ggplot2?
Model answer
Use
labs()to set plot labels, including the axis label and plot title.Explanation
The tutorial uses
labs()to replace a default count label and add a descriptive title. - 33
What effect did applying a white-background theme have on the demonstrated survival plot?
Model answer
It replaced ggplot2’s default gray background with a clean white background.
Explanation
The presenter preferred the white background for the plot’s appearance and presentation.
- 34
Why can copy-and-paste reuse make it quick to create a series of ggplot2 visualizations?
Model answer
After writing one plot, a user can reuse its structure and change only the mappings or labels needed for the next question.
Explanation
The tutorial repeatedly adapts an existing plot rather than writing each visualization from scratch.
- 35
What question does a histogram answer when analyzing passenger ages?
Model answer
It shows the distribution of ages by grouping numeric observations into intervals, or bins.
Explanation
The tutorial first uses a histogram to inspect the age distribution across all passengers.
- 36
How does changing a histogram’s bin width affect the plot?
Model answer
It changes how ages are grouped and therefore changes the histogram’s shape and level of detail.
Explanation
The tutorial uses five-year bins and notes that one-year or ten-year bins would produce different plots.
- 37
Why should an analyst inspect different bin widths rather than automatically accept ggplot2’s default?
Model answer
The default bin width may not be optimal, so comparing widths helps identify a grouping that represents the data reasonably.
Explanation
The tutorial recommends trying different widths because the chosen width affects the histogram’s appearance.
- 38
What does ggplot2 do when a plotted numeric variable contains missing values?
Model answer
It removes the missing observations from the plot and reports how many were removed, while warning that missing data may need further treatment.
Explanation
For age, the demonstration reported removing 177 missing values to construct the histogram from the available observations.
- 39
What did the overall age histogram show about the passenger age distribution?
Model answer
Many passengers were between about 20 and 40 years old, there were some children, and the distribution had a long tail toward older ages.
Explanation
The histogram showed comparatively few very young or older passengers and some passengers as old as about 80.
- 40
What additional information does filling age-histogram bars by survival status provide?
Model answer
It shows the relative survival and death counts within each age bin, helping reveal how survival patterns vary with age.
Explanation
The filled histogram extends the overall age distribution with survival outcomes for each age interval.
- 41
What is a box-and-whisker plot used to compare in the tutorial’s age analysis?
Model answer
It compares the age distributions of passengers who perished and passengers who survived.
Explanation
The plot maps survival status to one axis and age to the other, allowing the two groups’ age distributions to be compared.
- 42
What age-related pattern did the box-and-whisker plot suggest?
Model answer
Passengers who survived tended to be somewhat younger than passengers who perished, although the difference was not large.
Explanation
The relative positions of the plotted distributions suggested a modest age difference.
- 43
Why did the tutorial recommend using more than one type of visualization to examine the same data?
Model answer
Different plots reveal different aspects of a pattern; using multiple visualizations can provide a more thorough understanding than relying on one plot alone.
Explanation
The box plot suggested a general age difference, while the histogram better highlighted survival among children.
- 44
How are density plots related to histograms, and how do they differ visually?
Model answer
A density plot presents distribution information similar to a histogram but with a smoothed curve instead of bars.
Explanation
The tutorial notes that density plots may be easier for some audiences to read, while conveying comparable distribution information.
- 45
What does the
alphasetting control in a density plot?Model answer
It controls transparency, allowing overlapping plot elements to show through one another.
Explanation
The tutorial uses an alpha value of 0.5 to make the density shapes transparent and reveal overlaps.
- 46
How does faceting by ticket class and sex help analyze age-related survival?
Model answer
It separates the age and survival patterns into panels for combinations of class and sex, making group-specific differences easier to inspect.
Explanation
The panels provide a view of age distribution and survival across both categorical variables at once.
- 47
What does a faceted plot with age on an axis and survival mapped to fill allow an analyst to compare?
Model answer
It allows comparison of age distributions and survival outcomes across the categories used to form the panels.
Explanation
The tutorial combines age, survival, sex, and ticket class to examine how their patterns vary together.
- 48
What broad conclusion did the faceted age analysis support about survival?
Model answer
Age was relevant, but its relationship with survival depended on the combination of age, sex, and ticket class rather than age alone.
Explanation
The tutorial emphasizes that the combined variables provided a richer survival pattern than examining age in isolation.
- 49
What did the faceted analysis suggest about young passengers in second class?
Model answer
The youngest children in second class, both girls and boys, showed high survival in the displayed analysis.
Explanation
The second-class panels showed survival outcomes concentrated among the youngest passengers.
- 50
What did the analysis suggest about survival among older males in third class?
Model answer
Older males in third class had particularly poor survival outcomes.
Explanation
The third-class male panels showed many deaths among older passengers, consistent with low survival in that group.
- 51
Why might an analyst use both a density plot and a histogram for the same faceted data?
Model answer
The two plot types show related distribution and survival information in different visual forms, which can make patterns clearer or expose details one form obscures.
Explanation
The tutorial demonstrates both and notes that the histogram made some age-specific survival counts more apparent.
- 52
Why are intuitive visualizations especially useful when presenting analysis to a non-data-savvy audience?
Model answer
They help audiences recognize patterns and proportions visually without requiring them to interpret complex statistics or mathematical representations.
Explanation
The tutorial recommends using visualizations to communicate findings clearly and tell a data-based story.

Ask anything
We've read this whole study set, so questions about it get the best answers.