Concepts of the {ggplot2}
Package Pt. 2:
Solution Exercise 2
stat_summary()
stat_summary()
bikes %>%
group_by(season) %>%
summarize(count = sum(count)) %>%
ggplot(aes(x = season, y = count)) +
geom_point(size = 3) +
geom_linerange(
aes(ymin = 0, ymax = count)
) +
coord_polar(theta = "y") +
scale_x_discrete(
expand = c(.5, .5)
) +
scale_y_continuous(
limits = c(0, 7.5*10^6)
) +
theme_void()
bikes %>%
group_by(season) %>%
summarize(count = sum(count)) %>%
ggplot(aes(x = season, y = count)) +
geom_point(size = 3) +
geom_linerange(
aes(ymin = 0, ymax = count)
) +
coord_polar(theta = "y") +
scale_x_discrete(
expand = c(.5, .5)
) +
scale_y_continuous(
limits = c(0, 7.5*10^6)
) +
theme_void() +
theme(plot.margin = margin(rep(-100, 4)))
bikes %>%
group_by(season) %>%
summarize(count = sum(count)) %>%
ggplot(aes(x = season, y = count)) +
geom_point(size = 3) +
geom_linerange(
aes(ymin = 0, ymax = count)
) +
geom_text(
aes(label = season, y = 0)
) +
coord_polar(theta = "y") +
scale_x_discrete(
expand = c(.5, .5)
) +
scale_y_continuous(
limits = c(0, 7.5*10^6)
) +
theme_void() +
theme(plot.margin = margin(rep(-100, 4)))
bikes %>%
group_by(season) %>%
summarize(count = sum(count)) %>%
ggplot(aes(x = season, y = count)) +
geom_point(size = 3) +
geom_linerange(
aes(ymin = 0, ymax = count)
) +
geom_text(
aes(label = season, y = 0),
family = "Cabinet Grotesk", size = 4.5,
fontface = "bold", hjust = 1.15
) +
coord_polar(theta = "y") +
scale_x_discrete(
expand = c(.5, .5)
) +
scale_y_continuous(
limits = c(0, 7.5*10^6)
) +
theme_void() +
theme(plot.margin = margin(rep(-100, 4)))
bikes %>%
group_by(season) %>%
summarize(count = sum(count)) %>%
ggplot(aes(x = season, y = count)) +
geom_point(size = 3) +
geom_linerange(
aes(ymin = 0, ymax = count)
) +
geom_text(
aes(label = season, y = 0),
family = "Cabinet Grotesk", size = 4.5,
fontface = "bold", hjust = 1.15
) +
geom_text(
aes(label = paste0(round(count / 10^6, 1), "M")),
size = 4, vjust = -1, family = "Cabinet Grotesk"
) +
coord_polar(theta = "y") +
scale_x_discrete(
expand = c(.5, .5)
) +
scale_y_continuous(
limits = c(0, 7.5*10^6)
) +
theme_void() +
theme(plot.margin = margin(rep(-100, 4)))
bikes %>%
group_by(season) %>%
summarize(count = sum(count)) %>%
ggplot(aes(x = season, y = count)) +
geom_point(size = 3) +
geom_linerange(
aes(ymin = 0, ymax = count)
) +
geom_hline(yintercept = 0) +
geom_text(
aes(label = season, y = 0),
family = "Cabinet Grotesk", size = 4.5,
fontface = "bold", hjust = 1.15
) +
coord_polar(theta = "y") +
scale_x_discrete(
expand = c(.5, .5)
) +
scale_y_continuous(
limits = c(0, 7.5*10^6)
) +
theme_void() +
theme(plot.margin = margin(rep(-100, 4)))
bikes %>%
group_by(season) %>%
summarize(count = sum(count)) %>%
ggplot(aes(x = season, y = count)) +
geom_point(size = 3) +
geom_linerange(
aes(ymin = 0, ymax = count)
) +
geom_linerange(
xmin = .7, xmax = 4.3, y = 0
) +
geom_text(
aes(label = season, y = 0),
family = "Cabinet Grotesk", size = 4.5,
fontface = "bold", hjust = 1.15
) +
coord_polar(theta = "y") +
scale_x_discrete(
expand = c(.5, .5)
) +
scale_y_continuous(
limits = c(0, 7.5*10^6)
) +
theme_void() +
theme(plot.margin = margin(rep(-100, 4)))
bikes %>%
group_by(season) %>%
summarize(count = sum(count)) %>%
ggplot(aes(x = season, y = count)) +
geom_point(size = 3) +
geom_linerange(
aes(ymin = 0, ymax = count)
) +
annotate(
geom = "linerange",
xmin = .7, xmax = 4.3, y = 0
) +
geom_text(
aes(label = season, y = 0),
family = "Cabinet Grotesk", size = 4.5,
fontface = "bold", hjust = 1.15
) +
coord_polar(theta = "y") +
scale_x_discrete(
expand = c(.5, .5)
) +
scale_y_continuous(
limits = c(0, 7.5*10^6)
) +
theme_void() +
theme(plot.margin = margin(rep(-100, 4)))
stat_summary()
ggplot(bikes, aes(x = as.numeric(season), y = count)) +
stat_summary(
geom = "point", fun = "sum", size = 3
) +
stat_summary(
geom = "linerange", ymin = 0,
fun.max = function(y) sum(y)
) +
stat_summary(
geom = "text",
aes(
label = season,
y = 0
),
family = "Cabinet Grotesk", size = 4.5,
fontface = "bold", hjust = 1.15
) +
annotate(
geom = "linerange",
xmin = .7, xmax = 4.3, y = 0
) +
coord_polar(theta = "y") +
scale_x_discrete(
expand = c(.5, .5)
) +
scale_y_continuous(
limits = c(0, 7.5*10^6)
) +
theme_void() +
theme(plot.margin = margin(rep(-100, 4)))
Cédric Scherer // rstudio::conf // July 2022