generated from KSUDS/p2_data
-
Notifications
You must be signed in to change notification settings - Fork 1
/
waffle_example.R
44 lines (38 loc) · 1.26 KB
/
waffle_example.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
library(tidyverse)
library(waffle)
library(ggfittext)
httpgd::hgd()
httpgd::hgd_browse()
storms %>%
filter(year >= 2010) %>%
count(year, status) -> storms_df
ggplot(storms_df, aes(fill = status, values = n)) +
geom_waffle(color = "white", size = .25, n_rows = 10, flip = TRUE) +
facet_wrap(~year, nrow = 1, strip.position = "bottom") +
scale_x_discrete() +
scale_y_continuous(labels = function(x) x * 10, # make this multiplyer the same as n_rows
expand = c(0,0)) +
ggthemes::scale_fill_tableau(name=NULL) +
coord_equal() +
labs(
title = "Faceted Waffle Bar Chart",
subtitle = "{dplyr} storms data",
x = "Year",
y = "Count"
) +
theme_minimal(base_family = "Roboto Condensed") +
theme(panel.grid = element_blank(), axis.ticks.y = element_line()) +
guides(fill = guide_legend(reverse = TRUE))
## Example with heatmap
storms %>%
count(year, status) -> storms_df_all
storms_df_all %>%
ggplot(aes(x = year, y = status, fill = n)) +
geom_tile() +
geom_fit_text(aes(label = n), color = "white", size = 4, contrast = TRUE) +
scale_fill_viridis_c() +
coord_fixed()
# color scale sucks
# better labels
# theme issues
# think about axis labels, lines, size of grid