Skip to content

Commit

Permalink
updated cookbook graph axes
Browse files Browse the repository at this point in the history
  • Loading branch information
gisellerosetta committed Nov 27, 2024
1 parent 40de1a7 commit 0fa18e9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
5 changes: 4 additions & 1 deletion vignettes/cookbook/_annotations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ ggplot(life_exp_bar_data, aes(x = reorder(country, -lifeExp), y = lifeExp)) +
geom_text(aes(label = round(lifeExp, 1)),
nudge_y = -5, colour = "white") +
theme_af() +
scale_y_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0),
limits = c(0, 100),
breaks = c(seq(0, 100, 20)),
labels = c(seq(0, 100, 20))) +
labs(
x = NULL,
y = NULL,
Expand Down
42 changes: 30 additions & 12 deletions vignettes/cookbook/_chart-types.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ pop_bar_data <- gapminder |>
ggplot(pop_bar_data, aes(x = reorder(country, -pop), y = pop/(10^6))) +

Check warning on line 65 in vignettes/cookbook/_chart-types.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/cookbook/_chart-types.Rmd,line=65,col=61,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 65 in vignettes/cookbook/_chart-types.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/cookbook/_chart-types.Rmd,line=65,col=62,[spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call.
geom_col(fill = af_colour_values["dark-blue"]) +
theme_af() +
scale_y_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0),
limits = c(0, 350),
breaks = c(seq(0, 350, 50)),
labels = c(seq(0, 300, 50), "350 million")) +
labs(
x = NULL,
y = NULL,
title = "The U.S.A. is the most populous country in\nthe Americas",
subtitle = "Population of countries in the Americas (millions), 2007",
title = stringr::str_wrap("The U.S.A. is the most populous country in the Americas", 40),

Check warning on line 75 in vignettes/cookbook/_chart-types.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/cookbook/_chart-types.Rmd,line=75,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 93 characters.
subtitle = "Population of countries in the Americas, 2007",
caption = "Source: Gapminder"
)
)
```

A bar chart can sometimes look better with horizontal bars. This can also be a good option if your bar labels are long and difficult to display horizontally on the x axis. To produce a horizontal bar chart, swap the variables defined for x and y in `aes()` and make a few tweaks to `theme_af()`; draw grid lines for the x axis only by setting the `grid` argument, and draw an axis line for the y axis only by setting the `axis` argument.
Expand All @@ -83,12 +86,15 @@ A bar chart can sometimes look better with horizontal bars. This can also be a g
ggplot(pop_bar_data, aes(x = pop/(10^6), y = reorder(country, -pop))) +

Check warning on line 86 in vignettes/cookbook/_chart-types.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/cookbook/_chart-types.Rmd,line=86,col=33,[infix_spaces_linter] Put spaces around all infix operators.
geom_col(fill = af_colour_values["dark-blue"]) +
theme_af(grid = "x", axis = "y") +
scale_x_continuous(expand = c(0, 0)) +
scale_x_continuous(expand = c(0, 0),
limits = c(0, 350),
breaks = c(seq(0, 350, 50)),
labels = c(seq(0, 300, 50), "350 million")) +
labs(
x = NULL,
y = NULL,
title = "The U.S.A. is the most populous country in\nthe Americas",
subtitle = "Population of countries in the Americas (millions), 2007",
title = stringr::str_wrap("The U.S.A. is the most populous country in the Americas", 40),
subtitle = "Population of countries in the Americas, 2007",
caption = "Source: Gapminder"
)
```
Expand All @@ -109,7 +115,10 @@ grouped_bar_data <-
ggplot(grouped_bar_data,
aes(x = country, y = lifeExp, fill = as.factor(year))) +
geom_bar(stat = "identity", position = "dodge") +
scale_y_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0),
limits = c(0, 100),
breaks = c(seq(0, 100, 20)),
labels = c(seq(0, 100, 20))) +
theme_af(legend = "bottom") +
scale_fill_discrete_af() +
labs(
Expand Down Expand Up @@ -170,7 +179,10 @@ gapminder |>
colour = "white",
fill = af_colour_values["dark-blue"]) +
theme_af() +
scale_y_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0),
limits = c(0, 35),
breaks = c(seq(0, 35, 5)),
labels = c(seq(0, 35, 5))) +
labs(
x = NULL,
y = "Number of \ncountries",
Expand Down Expand Up @@ -273,12 +285,15 @@ pop_bar_data |>
) +
geom_col() +
theme_af(legend = "none") +
scale_y_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0),
limits = c(0, 350),
breaks = c(seq(0, 350, 50)),
labels = c(seq(0, 300, 50), "350 million")) +
scale_fill_discrete_af("focus", reverse = TRUE) +
labs(
x = NULL,
y = NULL,
title = "Brazil has the second highest population in\nthe Americas",
title = stringr::str_wrap("Brazil has the second highest population in the Americas", 40),
subtitle = "Population of countries in the Americas (millions), 2007",
caption = "Source: Gapminder"
)
Expand Down Expand Up @@ -314,7 +329,10 @@ p <-
geom_col(fill = af_colour_values["dark-blue"]) +
theme_af(ticks = "x") +
theme(text = element_text(family = "")) +
scale_y_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0),
limits = c(0, 100),
breaks = c(seq(0, 100, 20)),
labels = c(seq(0, 100, 20))) +
labs(
x = NULL,
y = NULL
Expand Down
5 changes: 4 additions & 1 deletion vignettes/cookbook/_customisations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ ggplot(life_exp_bar_data, aes(x = reorder(country, -lifeExp), y = lifeExp)) +
theme_af(axis = "xy") +
theme(axis.line = element_line(colour = "black"),
axis.ticks = element_line(colour = "black")) +
scale_y_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0),
limits = c(0, 100),
breaks = c(seq(0, 100, 20)),
labels = c(seq(0, 100, 20))) +
labs(
x = NULL,
y = NULL,
Expand Down

0 comments on commit 0fa18e9

Please sign in to comment.