01:00
Consider the covid_testing data frame.
What do you think a plot would look like in which:
pan_day
(day of the pandemic), and01:00
What is the name of this kind of plot?
Type the answer into the chat!
Type the following code in the RStudio console to make a graph.
Pay attention to the spelling, capitalization, and parentheses!
ggplot(data = covid_testing) +
geom_histogram(mapping = aes(x = pan_day))
01:00
ggplot(data = covid_testing) +
geom_histogram(mapping = aes(x = pan_day))
A data set is tidy if:
geom_histogram()
geom_dotplot()
geom_bar()
geom_boxplot()
geom_point()
geom_line()
aes(x = a, y = b, color = c)
In addition to x/y position and color, what other aesthetic mappings can you think of?
(Hint: things that don’t change to fit the data, like the background color of a graph, aren’t mappings).
Type your answers in the chat!
From Fundamentals of Data Visualization, by Claus Wilke, licensed under CC-BY-NC-ND
Open 02 - Visualize.Qmd
. Work through the exercises of the section titled “Your Turn 5”.
Stop when it says “Stop Here”.
Click “thumbs up” when you’re done!
05:00
ggplot(data = covid_testing) +
geom_histogram(mapping = aes(x = pan_day), fill = "blue")
ggplot(data = covid_testing) +
geom_histogram(mapping = aes(x = pan_day,
fill = result))
Notice what’s inside the geom_histogram():
mapping = aes(x = pan_day, fill = result)
Is “fill” inside or outside of mapping?
ggplot(data = covid_testing) +
geom_histogram(mapping = aes(x = pan_day),
fill = "blue")
Notice what’s inside the geom_histogram:
mapping = aes(x = pan_day), fill = "blue"
Is “fill” inside or outside of mapping?
Return to 02 - Visualize.qmd
. Work through the exercises of the section titled “Your Turn 6.”
Click “thumbs up” when you’re done!
05:00
ggplot2 is a package that provides a grammar of graphics. You can create any type of plot using a simple template to which you provide:
A tidy data frame, in which each variable is in its own column, each observation is in its own row, each value is in its own cell;
A geom function, which tells R what kind of plot to make; and
Aesthetic mappings, which tell R how to represent data as graphical markings on the plot.
ggplot(covid_testing) +
geom_histogram(
mapping = aes(x = pan_day, fill = result),
position = position_dodge()
)
ggplot(covid_testing) +
geom_histogram(
mapping = aes(x = pan_day, fill = result),
position = position_dodge()
) +
theme_light()
library(colorspace)
cols <- c(
"invalid" = "grey80",
qualitative_hcl(2, palette = "dark3")
)
ggplot(covid_testing) +
geom_histogram(
mapping = aes(x = pan_day, fill = result),
position = position_dodge()
) +
theme_light() +
scale_fill_manual(values = cols)
ggplot(covid_testing) +
geom_histogram(
mapping = aes(x = pan_day, fill = result)
) +
theme_light() +
scale_fill_manual(values = cols) +
facet_wrap(~demo_group)
ggplot(covid_testing) +
geom_histogram(
mapping = aes(x = pan_day, fill = result)
) +
theme_light() +
scale_fill_manual(values = cols) +
facet_wrap(~demo_group) +
coord_polar()
ggplot(data = data_frame) + # Required
geom_function(mapping = aes(mappings)) + # Required
theme_function + # Optional
scale_function + # Optional
facet_function + # Optional
coordinate_function + # Optional
...
Our next topic is:
Arcus Education / Children’s Hospital of Philadelphia (CHOP) R User Group