From d8b251db78f5ef0fa5c00cffc8479d742bd71d1b Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Wed, 23 Jul 2025 17:33:37 +0100 Subject: [PATCH 01/20] Add link to gov.scot (closes #60) --- _pkgdown.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index 1cc32ff..a85cf24 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -19,6 +19,10 @@ authors: Alice Hannah GitHub profile>" Scottish Government: html: "Scottish Government  \ + \ + \ + Scottish Government Website>\ +   \ \ \ Email Scottish Government>\ From fc80fbe1f486d68e07a8ebfee1e6dfe41419804a Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Wed, 23 Jul 2025 17:35:11 +0100 Subject: [PATCH 02/20] Update font-awesome coding --- _pkgdown.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index a85cf24..0ff3908 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -12,10 +12,10 @@ authors: Alice Hannah: html: "Alice Hannah  \ \ - \ + \ Email Alice Hannah>  \ \ - \ + \ Alice Hannah GitHub profile>" Scottish Government: html: "Scottish Government  \ @@ -24,11 +24,11 @@ authors: Scottish Government Website>\   \ \ - \ + \ Email Scottish Government>\   \ \ - \ + \ Scottish Government GitHub profile>\ " sidebar: From b4ac18d31a658492f7374138c937b37ed540a484 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 24 Jul 2025 10:47:29 +0100 Subject: [PATCH 03/20] Change data used in readme bar charts (#37) --- README.Rmd | 31 +- README.md | 31 +- man/figures/README-ex1-1.svg | 601 +++++++++++++++++++---------------- man/figures/README-ex2-1.svg | 550 +++++++++++++++++--------------- 4 files changed, 655 insertions(+), 558 deletions(-) diff --git a/README.Rmd b/README.Rmd index 97c7b76..3495dce 100644 --- a/README.Rmd +++ b/README.Rmd @@ -85,21 +85,25 @@ The easiest way to use sgplot is by adding `use_sgplot()` to the beginning of yo #### Example 1: Plot with one colour using ggplot2 defaults ```{r ex1, fig.alt = ex1_alt} +library(sgplot) library(ggplot2) library(dplyr) library(gapminder) gapminder |> - filter(year == 2007 & continent == "Europe") |> - slice_max(order_by = lifeExp, n = 5) |> + filter(year == 2007 & continent == "Americas") |> + slice_max(order_by = pop, n = 5) |> ggplot() + - geom_col(aes(x = reorder(country, -lifeExp), y = lifeExp)) + - scale_y_continuous(expand = c(0, 0)) + + geom_col(aes(x = reorder(country, -pop), y = pop)) + + scale_y_continuous( + labels = scales::label_number(scale = 1E-6), + expand = c(0, 0) + ) + labs( x = NULL, y = NULL, - title = "Iceland has the highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "The United States is the most populous country in the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` @@ -110,16 +114,19 @@ gapminder |> sgplot::use_sgplot() gapminder |> - filter(year == 2007 & continent == "Europe") |> - slice_max(order_by = lifeExp, n = 5) |> + filter(year == 2007 & continent == "Americas") |> + slice_max(order_by = pop, n = 5) |> ggplot() + - geom_col(aes(x = reorder(country, -lifeExp), y = lifeExp)) + - scale_y_continuous(expand = c(0, 0)) + + geom_col(aes(x = reorder(country, -pop), y = pop)) + + scale_y_continuous( + labels = scales::label_number(scale = 1E-6), + expand = c(0, 0) + ) + labs( x = NULL, y = NULL, - title = "Iceland has the highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "The United States is the most populous country \nin the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` diff --git a/README.md b/README.md index 2c5afbb..a337902 100644 --- a/README.md +++ b/README.md @@ -79,21 +79,25 @@ colour palettes and use `theme_sg()`. #### Example 1: Plot with one colour using ggplot2 defaults ``` r +library(sgplot) library(ggplot2) library(dplyr) library(gapminder) gapminder |> - filter(year == 2007 & continent == "Europe") |> - slice_max(order_by = lifeExp, n = 5) |> + filter(year == 2007 & continent == "Americas") |> + slice_max(order_by = pop, n = 5) |> ggplot() + - geom_col(aes(x = reorder(country, -lifeExp), y = lifeExp)) + - scale_y_continuous(expand = c(0, 0)) + + geom_col(aes(x = reorder(country, -pop), y = pop)) + + scale_y_continuous( + labels = scales::label_number(scale = 1E-6), + expand = c(0, 0) + ) + labs( x = NULL, y = NULL, - title = "Iceland has the highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "The United States is the most populous country in the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` @@ -106,16 +110,19 @@ gapminder |> sgplot::use_sgplot() gapminder |> - filter(year == 2007 & continent == "Europe") |> - slice_max(order_by = lifeExp, n = 5) |> + filter(year == 2007 & continent == "Americas") |> + slice_max(order_by = pop, n = 5) |> ggplot() + - geom_col(aes(x = reorder(country, -lifeExp), y = lifeExp)) + - scale_y_continuous(expand = c(0, 0)) + + geom_col(aes(x = reorder(country, -pop), y = pop)) + + scale_y_continuous( + labels = scales::label_number(scale = 1E-6), + expand = c(0, 0) + ) + labs( x = NULL, y = NULL, - title = "Iceland has the highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "The United States is the most populous country in the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` diff --git a/man/figures/README-ex1-1.svg b/man/figures/README-ex1-1.svg index 715c317..bd2f4cd 100644 --- a/man/figures/README-ex1-1.svg +++ b/man/figures/README-ex1-1.svg @@ -3,518 +3,561 @@ - + - + - + - + - + - + - + - + - + - + - - + - + - + - + - + - + - + - + - + - + - + - + + - + - + + + + + + + + + + + + + + + + - + - + - + - + + - + - + - + - + - - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + - + - + - + - - + - + - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - + - - + - - + + + - - + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + - - - - - + + + + + + - - - - - - + + + + + + + + - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/man/figures/README-ex2-1.svg b/man/figures/README-ex2-1.svg index 4ccedb3..dcfd729 100644 --- a/man/figures/README-ex2-1.svg +++ b/man/figures/README-ex2-1.svg @@ -3,456 +3,496 @@ - + - + - + - + - + - + - + - + - + - + - - + - + - + - + - + - + - + - + - + - + - + + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + - + - + - + - - + - + - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + - + - + - + - + - + - + - + - + - - - - - - - + - - + - - + + + - - + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + - - - - - + + + + + + - - - - - - + + + + + + + + - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + From c5baecb587065a5c905e7599b5f9fbce63fe2d16 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 24 Jul 2025 14:36:17 +0100 Subject: [PATCH 04/20] Update bar chart examples in cookbook (#37) --- vignettes/cookbook/_annotations.Rmd | 17 +++++--- vignettes/cookbook/_chart-types.Rmd | 55 +++++++++++++++++--------- vignettes/cookbook/_customisations.Rmd | 44 ++++++++++++--------- 3 files changed, 72 insertions(+), 44 deletions(-) diff --git a/vignettes/cookbook/_annotations.Rmd b/vignettes/cookbook/_annotations.Rmd index 387edcb..fe3324d 100644 --- a/vignettes/cookbook/_annotations.Rmd +++ b/vignettes/cookbook/_annotations.Rmd @@ -85,17 +85,22 @@ Annotations may also be used to add value labels to a bar chart. Note that `geom ```{r annotations-3} #| fig.alt = "A bar chart with white text labels at the end of each bar." -ggplot(bar_data, aes(x = reorder(country, -lifeExp), y = lifeExp)) + +ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + geom_col(fill = sg_colour_values["dark-blue"]) + - geom_text(aes(label = round(lifeExp, 1)), - nudge_y = -5, colour = "white") + + geom_text(aes(label = format(pop, big.mark = ",")), + nudge_y = -max(bar_data$pop) * 0.05, + colour = "white") + theme_sg() + - scale_y_continuous(expand = c(0, 0)) + + scale_y_continuous( + labels = scales::label_number(scale = 1E-6), + limits = c(0, max(bar_data$pop) * 1.02), + expand = c(0, 0) + ) + labs( x = NULL, y = NULL, - title = "Iceland has the highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "The United States is the most populous country \nin the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` diff --git a/vignettes/cookbook/_chart-types.Rmd b/vignettes/cookbook/_chart-types.Rmd index e56e485..71970bf 100644 --- a/vignettes/cookbook/_chart-types.Rmd +++ b/vignettes/cookbook/_chart-types.Rmd @@ -56,22 +56,26 @@ An example with line labels and no legend can be found in the [Adding annotation ```{r bar-data} bar_data <- gapminder |> - filter(year == 2007 & continent == "Europe") |> - slice_max(order_by = lifeExp, n = 5) + filter(year == 2007 & continent == "Americas") |> + slice_max(order_by = pop, n = 5) ``` ```{r bar-chart-1} #| fig.alt = "A bar chart using sgplot theme and dark blue colour." -ggplot(bar_data, aes(x = reorder(country, -lifeExp), y = lifeExp)) + +ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + geom_col(fill = sg_colour_values["dark-blue"]) + theme_sg() + - scale_y_continuous(expand = c(0, 0)) + + scale_y_continuous( + labels = scales::label_number(scale = 1E-6), + limits = c(0, max(bar_data$pop) * 1.02), + expand = c(0, 0) + ) + labs( x = NULL, y = NULL, - title = "Iceland has the highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "The United States is the most populous country \nin the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` @@ -81,15 +85,19 @@ A bar chart can sometimes look better with horizontal bars. This can also be a g ```{r bar-chart-2} #| fig.alt = "A horizontal bar chart using sgplot theme and dark blue colour." -ggplot(bar_data, aes(x = lifeExp, y = reorder(country, lifeExp))) + +ggplot(bar_data, aes(x = pop, y = reorder(country, pop))) + geom_col(fill = sg_colour_values["dark-blue"]) + theme_sg(grid = "x", axis = "y") + - scale_x_continuous(expand = c(0, 0)) + + scale_x_continuous( + labels = scales::label_number(scale = 1E-6), + limits = c(0, max(bar_data$pop) * 1.02), + expand = c(0, 0) + ) + labs( x = NULL, y = NULL, - title = "Iceland has the highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "The United States is the most populous country \nin the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` @@ -265,22 +273,26 @@ stacked_bar_data |> ## Focus charts ```{r focus-chart} -#| fig.alt = "A bar chart with the bar for Sweden highlighted in dark blue and other bars in grey." +#| fig.alt = "A bar chart with the bar for Brazil highlighted in dark blue and other bars in grey." bar_data |> ggplot( - aes(x = reorder(country, -lifeExp), y = lifeExp, - fill = country == "Sweden") + aes(x = reorder(country, -pop), y = pop, + fill = country == "Brazil") ) + geom_col() + theme_sg(legend = "none") + - scale_y_continuous(expand = c(0, 0)) + + scale_y_continuous( + labels = scales::label_number(scale = 1E-6), + limits = c(0, max(bar_data$pop) * 1.02), + expand = c(0, 0) + ) + scale_fill_discrete_sg("focus", reverse = TRUE) + labs( x = NULL, y = NULL, - title = "Sweden has the fourth highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "Brazil has the second highest population in the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` @@ -302,13 +314,18 @@ p <- # Format text for tooltips mutate(tooltip = paste0( "Country: ", country, "\n", - "Life Expectancy: ", round(lifeExp, 1) + "Population: ", format(pop, big.mark = ",") )) |> - ggplot(aes(x = reorder(country, -lifeExp), y = lifeExp, text = tooltip)) + + ggplot(aes(x = reorder(country, -pop), y = pop, text = tooltip)) + geom_col(fill = sg_colour_values["dark-blue"]) + theme_sg(ticks = "x") + theme(text = element_text(family = "")) + - scale_y_continuous(expand = c(0, 0)) + + scale_y_continuous( + labels = scales::label_number(scale = 1E-6, + suffix = "m"), + limits = c(0, max(bar_data$pop) * 1.02), + expand = c(0, 0) + ) + labs( x = NULL, y = NULL diff --git a/vignettes/cookbook/_customisations.Rmd b/vignettes/cookbook/_customisations.Rmd index 2ab8c7d..9cbddf4 100644 --- a/vignettes/cookbook/_customisations.Rmd +++ b/vignettes/cookbook/_customisations.Rmd @@ -10,7 +10,7 @@ To control the order of bars in a chart, wrap the variable you want to arrange w #| fig.alt = "A bar chart using sgplot theme and dark blue colour with bars sorted in decreasing order by life expectancy." bar_data |> - ggplot(aes(x = lifeExp, y = reorder(country, lifeExp))) + + ggplot(aes(x = pop, y = reorder(country, pop))) + geom_col(fill = sg_colour_values["dark-blue"]) + theme_sg(axis = "y", grid = "x") ``` @@ -29,8 +29,8 @@ last_plot() + labs( x = NULL, y = NULL, - title = "Iceland has the highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "The United States is the most populous country \nin the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` @@ -58,9 +58,9 @@ Axis limits, breaks and labels for continuous variables can be controlled using last_plot() + scale_x_continuous(expand = c(0, 0), - limits = c(0, 85), - breaks = seq(0, 80, 20), - labels = c(seq(0, 70, 20), "80 years")) + limits = c(0, 3e8 * 1.1), + breaks = seq(0, 3e8, 5e7), + labels = c(seq(0, 250, 50), "300 million")) ``` Note that further calls to `scale_x/y_continuous` will overwrite previous calls, hence why `expand = c(0, 0)` has been included again in this example. @@ -138,21 +138,24 @@ If text is too long, it may be cut off or distort the dimensions of the chart. #| fig.alt = "A bar chart with end of main title text not visible and long y axis title skewing the dimensions of the chart." plot <- - ggplot(bar_data, aes(x = reorder(country, -lifeExp), y = lifeExp)) + + ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + geom_col(fill = sg_colour_values["dark-blue"]) + theme_sg() + - scale_y_continuous(expand = c(0, 0)) + + scale_y_continuous( + labels = scales::label_number(scale = 1E-6), + limits = c(0, max(bar_data$pop) * 1.02), + expand = c(0, 0) + ) + labs( x = NULL, - subtitle = "Life expectancy in European countries, 2007", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) plot + labs( - y = "Percentage of countries", - title = paste("Iceland has the highest life expectancy in Europe", - "followed closely by Switzerland") + y = "Population of countries", + title = "The United States is the most populous country in the Americas", ) ``` @@ -163,10 +166,9 @@ There are two suggested ways to solve this issue; Insert `\n` within a string to plot + labs( - y = "Percentage\nof countries", + y = "Population\nof countries", title = stringr::str_wrap( - paste("Iceland has the highest life expectancy in Europe", - "followed closely by Switzerland"), + "The United States is the most populous country in the Americas", width = 50 ) ) @@ -180,17 +182,21 @@ If you find you need to adjust theme elements for your chart, this can be done u ```{r adjust-theme} #| fig.alt = "A bar chart using sgplot theme and dark blue colour, with axis lines and ticks coloured black." -ggplot(bar_data, aes(x = reorder(country, -lifeExp), y = lifeExp)) + +ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + geom_col(fill = sg_colour_values["dark-blue"]) + theme_sg(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( + labels = scales::label_number(scale = 1E-6), + limits = c(0, max(bar_data$pop) * 1.02), + expand = c(0, 0) + ) + labs( x = NULL, y = NULL, - title = "Iceland has the highest life expectancy in Europe", - subtitle = "Life expectancy in European countries, 2007", + title = "The United States is the most populous country \nin the Americas", + subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` From 7f4d515ae2042833f076f42dc23b384f3ef7b23c Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 24 Jul 2025 13:39:21 +0000 Subject: [PATCH 05/20] Re-build README.md --- README.md | 10 +- man/figures/README-ex1-1.svg | 612 +++++++++++++++++------------------ man/figures/README-ex2-1.svg | 572 ++++++++++++++++---------------- 3 files changed, 598 insertions(+), 596 deletions(-) diff --git a/README.md b/README.md index a337902..1352909 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,8 @@ gapminder |> ggplot() + geom_col(aes(x = reorder(country, -pop), y = pop)) + scale_y_continuous( - labels = scales::label_number(scale = 1E-6), - expand = c(0, 0) + labels = scales::label_number(scale = 1E-6), + expand = c(0, 0) ) + labs( x = NULL, @@ -115,13 +115,13 @@ gapminder |> ggplot() + geom_col(aes(x = reorder(country, -pop), y = pop)) + scale_y_continuous( - labels = scales::label_number(scale = 1E-6), - expand = c(0, 0) + labels = scales::label_number(scale = 1E-6), + expand = c(0, 0) ) + labs( x = NULL, y = NULL, - title = "The United States is the most populous country in the Americas", + title = "The United States is the most populous country \nin the Americas", subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) diff --git a/man/figures/README-ex1-1.svg b/man/figures/README-ex1-1.svg index bd2f4cd..b298d18 100644 --- a/man/figures/README-ex1-1.svg +++ b/man/figures/README-ex1-1.svg @@ -3,561 +3,561 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - - - + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/man/figures/README-ex2-1.svg b/man/figures/README-ex2-1.svg index dcfd729..430b878 100644 --- a/man/figures/README-ex2-1.svg +++ b/man/figures/README-ex2-1.svg @@ -3,496 +3,498 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - - - + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b06929802f5a3135a98eb683dfddc456227fecde Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Tue, 29 Jul 2025 14:58:32 +0100 Subject: [PATCH 06/20] Simplify scale controls for examples --- vignettes/cookbook/_annotations.Rmd | 4 ++-- vignettes/cookbook/_chart-types.Rmd | 17 ++++++++--------- vignettes/cookbook/_customisations.Rmd | 8 ++++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/vignettes/cookbook/_annotations.Rmd b/vignettes/cookbook/_annotations.Rmd index fe3324d..547fc44 100644 --- a/vignettes/cookbook/_annotations.Rmd +++ b/vignettes/cookbook/_annotations.Rmd @@ -92,8 +92,8 @@ ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + colour = "white") + theme_sg() + scale_y_continuous( - labels = scales::label_number(scale = 1E-6), - limits = c(0, max(bar_data$pop) * 1.02), + labels = \(x) x / 1e6, + limits = c(0, 3e8 * 1.02), expand = c(0, 0) ) + labs( diff --git a/vignettes/cookbook/_chart-types.Rmd b/vignettes/cookbook/_chart-types.Rmd index 71970bf..3630b1a 100644 --- a/vignettes/cookbook/_chart-types.Rmd +++ b/vignettes/cookbook/_chart-types.Rmd @@ -67,8 +67,8 @@ ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + geom_col(fill = sg_colour_values["dark-blue"]) + theme_sg() + scale_y_continuous( - labels = scales::label_number(scale = 1E-6), - limits = c(0, max(bar_data$pop) * 1.02), + labels = \(x) x / 1e6, + limits = c(0, 3e8 * 1.02), expand = c(0, 0) ) + labs( @@ -89,8 +89,8 @@ ggplot(bar_data, aes(x = pop, y = reorder(country, pop))) + geom_col(fill = sg_colour_values["dark-blue"]) + theme_sg(grid = "x", axis = "y") + scale_x_continuous( - labels = scales::label_number(scale = 1E-6), - limits = c(0, max(bar_data$pop) * 1.02), + labels = \(x) x / 1e6, + limits = c(0, 3e8 * 1.02), expand = c(0, 0) ) + labs( @@ -283,8 +283,8 @@ bar_data |> geom_col() + theme_sg(legend = "none") + scale_y_continuous( - labels = scales::label_number(scale = 1E-6), - limits = c(0, max(bar_data$pop) * 1.02), + labels = \(x) x / 1e6, + limits = c(0, 3e8 * 1.02), expand = c(0, 0) ) + scale_fill_discrete_sg("focus", reverse = TRUE) + @@ -321,9 +321,8 @@ p <- theme_sg(ticks = "x") + theme(text = element_text(family = "")) + scale_y_continuous( - labels = scales::label_number(scale = 1E-6, - suffix = "m"), - limits = c(0, max(bar_data$pop) * 1.02), + labels = \(x) x / 1e6, + limits = c(0, 3e8 * 1.02), expand = c(0, 0) ) + labs( diff --git a/vignettes/cookbook/_customisations.Rmd b/vignettes/cookbook/_customisations.Rmd index 9cbddf4..7f205e2 100644 --- a/vignettes/cookbook/_customisations.Rmd +++ b/vignettes/cookbook/_customisations.Rmd @@ -142,8 +142,8 @@ plot <- geom_col(fill = sg_colour_values["dark-blue"]) + theme_sg() + scale_y_continuous( - labels = scales::label_number(scale = 1E-6), - limits = c(0, max(bar_data$pop) * 1.02), + labels = \(x) x / 1e6, + limits = c(0, 3e8 * 1.02), expand = c(0, 0) ) + labs( @@ -188,8 +188,8 @@ ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + theme(axis.line = element_line(colour = "black"), axis.ticks = element_line(colour = "black")) + scale_y_continuous( - labels = scales::label_number(scale = 1E-6), - limits = c(0, max(bar_data$pop) * 1.02), + labels = \(x) x / 1e6, + limits = c(0, 3e8 * 1.02), expand = c(0, 0) ) + labs( From 816b798ce939acc0b18955327a6f89ebcdf61570 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Tue, 29 Jul 2025 15:57:05 +0100 Subject: [PATCH 07/20] Fix typo --- vignettes/cookbook/_customisations.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/cookbook/_customisations.Rmd b/vignettes/cookbook/_customisations.Rmd index 7f205e2..f7693e3 100644 --- a/vignettes/cookbook/_customisations.Rmd +++ b/vignettes/cookbook/_customisations.Rmd @@ -51,7 +51,7 @@ The equivalent adjustment can be made for the y axis using `scale_y_continuous`. ### Changing axis limits, breaks and labels -Axis limits, breaks and labels for continuous variables can be controlled using `scale_x/y_continuous()`. For discrete variables, labels can be changes using `scale_x/y_discrete()` or alternatively by recoding the variable in the data before creating a chart. +Axis limits, breaks and labels for continuous variables can be controlled using `scale_x/y_continuous()`. For discrete variables, labels can be changed using `scale_x/y_discrete()` or alternatively by recoding the variable in the data before creating a chart. ```{r axis-limits-breaks-labels} #| fig.alt = "A bar chart with fewer x axis breaks and edited labels." From 943f5c992a349819684c8fb3d99ee00164102ee1 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Wed, 30 Jul 2025 10:15:00 +0100 Subject: [PATCH 08/20] Tweak subtitle/axis label --- vignettes/cookbook/_customisations.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vignettes/cookbook/_customisations.Rmd b/vignettes/cookbook/_customisations.Rmd index f7693e3..0a1f082 100644 --- a/vignettes/cookbook/_customisations.Rmd +++ b/vignettes/cookbook/_customisations.Rmd @@ -148,13 +148,13 @@ plot <- ) + labs( x = NULL, - subtitle = "Population of countries in the Americas (millions), 2007", + subtitle = "Population of countries in the Americas, 2007", caption = "Source: Gapminder" ) plot + labs( - y = "Population of countries", + y = "Population (millions)", title = "The United States is the most populous country in the Americas", ) ``` @@ -166,7 +166,7 @@ There are two suggested ways to solve this issue; Insert `\n` within a string to plot + labs( - y = "Population\nof countries", + y = "Population\n(millions)", title = stringr::str_wrap( "The United States is the most populous country in the Americas", width = 50 From c9ed93b7715a470b04977dffbef5ffbb3eb2fdbd Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Wed, 30 Jul 2025 10:44:28 +0100 Subject: [PATCH 09/20] Restructure preamble (#56) * Use headings instead of bold text --- vignettes/cookbook.Rmd | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/vignettes/cookbook.Rmd b/vignettes/cookbook.Rmd index e3478a7..14b5190 100644 --- a/vignettes/cookbook.Rmd +++ b/vignettes/cookbook.Rmd @@ -22,11 +22,9 @@ This cookbook provides examples of the code used to produce various chart types If there is a chart type or task which you think would be useful to include here, please [submit a suggestion](https://github.com/scotgovanalysis/sgplot/issues/new?assignees=alice-hannah&labels=documentation&title=Cookbook+suggestion). -**use_sgplot**
-The examples in this cookbook use the sgplot theme and colour functions explicitly, however it may be easier to make use of the `use_sgplot()` function if your charts all require a similar style. More information on `use_sgplot` can be found on the [homepage](https://scotgovanalysis.github.io/sgplot/#use-sgplot-as-default). +## Getting started -**Note on use of titles, subtitles and captions**
-Titles, subtitles and captions have been embedded in the charts in this cookbook for demonstration purposes. However, for accessibility reasons, it is usually preferable to provide titles in the body of the page rather than embedded within the image of the plot. +### Required packages The following packages are required to produce the example charts in this cookbook: @@ -39,6 +37,14 @@ library(dplyr) library(gapminder) ``` +### Use of titles, subtitles and captions + +Titles, subtitles and captions have been embedded in the charts in this cookbook for demonstration purposes. However, for accessibility reasons, it is usually preferable to provide titles in the body of the page rather than embedded within the image of the plot. + +### use_sgplot + +The examples in this cookbook use the sgplot theme and colour functions explicitly, however it may be easier to make use of the `use_sgplot()` function if your charts all require a similar style. More information on `use_sgplot` can be found on the [sgplot homepage](https://scotgovanalysis.github.io/sgplot/#use-sgplot-as-default). + ```{r chart-types, child = "cookbook/_chart-types.Rmd"} ``` From 613ba6e86d0099b604bac517706f3b9c0dbbd756 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Wed, 30 Jul 2025 10:55:04 +0100 Subject: [PATCH 10/20] Add link to AF guidance on chart titles --- vignettes/cookbook.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/cookbook.Rmd b/vignettes/cookbook.Rmd index 14b5190..2bb5c08 100644 --- a/vignettes/cookbook.Rmd +++ b/vignettes/cookbook.Rmd @@ -39,7 +39,7 @@ library(gapminder) ### Use of titles, subtitles and captions -Titles, subtitles and captions have been embedded in the charts in this cookbook for demonstration purposes. However, for accessibility reasons, it is usually preferable to provide titles in the body of the page rather than embedded within the image of the plot. +Titles, subtitles and captions have been embedded in the charts in this cookbook for demonstration purposes. However, for accessibility reasons, it is usually preferable to provide titles in the body of the page rather than embedded within the image of the plot. For more guidance on the placement of chart titles, see the [Analysis Function charts guidance](https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-charts/#section-5). ### use_sgplot From 15f9d3bbfdfa6ba18991d7476f49548a7b441fc5 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Wed, 30 Jul 2025 11:41:50 +0100 Subject: [PATCH 11/20] Convert vignettes to articles (closes #66) --- .Rbuildignore | 1 + DESCRIPTION | 15 +++------------ vignettes/{ => articles}/.gitignore | 0 vignettes/{ => articles}/accessibility.Rmd | 0 vignettes/{ => articles}/colours.Rmd | 0 vignettes/{ => articles}/cookbook.Rmd | 0 .../{ => articles}/cookbook/_acknowledgments.Rmd | 0 .../{ => articles}/cookbook/_annotations.Rmd | 0 .../{ => articles}/cookbook/_chart-types.Rmd | 0 .../{ => articles}/cookbook/_colour-palettes.Rmd | 0 .../{ => articles}/cookbook/_customisations.Rmd | 0 vignettes/{ => articles}/saving.Rmd | 0 12 files changed, 4 insertions(+), 12 deletions(-) rename vignettes/{ => articles}/.gitignore (100%) rename vignettes/{ => articles}/accessibility.Rmd (100%) rename vignettes/{ => articles}/colours.Rmd (100%) rename vignettes/{ => articles}/cookbook.Rmd (100%) rename vignettes/{ => articles}/cookbook/_acknowledgments.Rmd (100%) rename vignettes/{ => articles}/cookbook/_annotations.Rmd (100%) rename vignettes/{ => articles}/cookbook/_chart-types.Rmd (100%) rename vignettes/{ => articles}/cookbook/_colour-palettes.Rmd (100%) rename vignettes/{ => articles}/cookbook/_customisations.Rmd (100%) rename vignettes/{ => articles}/saving.Rmd (100%) diff --git a/.Rbuildignore b/.Rbuildignore index 24e97c8..ed7d305 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -12,3 +12,4 @@ ^Meta$ ^cran-comments\.md$ ^CRAN-SUBMISSION$ +^vignettes/articles$ diff --git a/DESCRIPTION b/DESCRIPTION index 64cf46d..03104b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,22 +19,13 @@ Imports: lifecycle, rlang, scales -Suggests: +Suggests: dplyr, - gapminder, - glue, gt, - knitr, - plotly, - purrr, - rmarkdown, - stringr, testthat (>= 2.1.0), - tibble, - tidyr -VignetteBuilder: - knitr + tibble Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 +Config/Needs/website: rmarkdown diff --git a/vignettes/.gitignore b/vignettes/articles/.gitignore similarity index 100% rename from vignettes/.gitignore rename to vignettes/articles/.gitignore diff --git a/vignettes/accessibility.Rmd b/vignettes/articles/accessibility.Rmd similarity index 100% rename from vignettes/accessibility.Rmd rename to vignettes/articles/accessibility.Rmd diff --git a/vignettes/colours.Rmd b/vignettes/articles/colours.Rmd similarity index 100% rename from vignettes/colours.Rmd rename to vignettes/articles/colours.Rmd diff --git a/vignettes/cookbook.Rmd b/vignettes/articles/cookbook.Rmd similarity index 100% rename from vignettes/cookbook.Rmd rename to vignettes/articles/cookbook.Rmd diff --git a/vignettes/cookbook/_acknowledgments.Rmd b/vignettes/articles/cookbook/_acknowledgments.Rmd similarity index 100% rename from vignettes/cookbook/_acknowledgments.Rmd rename to vignettes/articles/cookbook/_acknowledgments.Rmd diff --git a/vignettes/cookbook/_annotations.Rmd b/vignettes/articles/cookbook/_annotations.Rmd similarity index 100% rename from vignettes/cookbook/_annotations.Rmd rename to vignettes/articles/cookbook/_annotations.Rmd diff --git a/vignettes/cookbook/_chart-types.Rmd b/vignettes/articles/cookbook/_chart-types.Rmd similarity index 100% rename from vignettes/cookbook/_chart-types.Rmd rename to vignettes/articles/cookbook/_chart-types.Rmd diff --git a/vignettes/cookbook/_colour-palettes.Rmd b/vignettes/articles/cookbook/_colour-palettes.Rmd similarity index 100% rename from vignettes/cookbook/_colour-palettes.Rmd rename to vignettes/articles/cookbook/_colour-palettes.Rmd diff --git a/vignettes/cookbook/_customisations.Rmd b/vignettes/articles/cookbook/_customisations.Rmd similarity index 100% rename from vignettes/cookbook/_customisations.Rmd rename to vignettes/articles/cookbook/_customisations.Rmd diff --git a/vignettes/saving.Rmd b/vignettes/articles/saving.Rmd similarity index 100% rename from vignettes/saving.Rmd rename to vignettes/articles/saving.Rmd From 05c83e9c88b7dca3d1c4923bf8401c8408693ff4 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Wed, 30 Jul 2025 11:41:50 +0100 Subject: [PATCH 12/20] Convert vignettes to articles (closes #66) --- .Rbuildignore | 1 + DESCRIPTION | 15 +++------------ NEWS.md | 4 ++++ vignettes/{ => articles}/.gitignore | 0 vignettes/{ => articles}/accessibility.Rmd | 0 vignettes/{ => articles}/colours.Rmd | 0 vignettes/{ => articles}/cookbook.Rmd | 0 .../{ => articles}/cookbook/_acknowledgments.Rmd | 0 .../{ => articles}/cookbook/_annotations.Rmd | 0 .../{ => articles}/cookbook/_chart-types.Rmd | 0 .../{ => articles}/cookbook/_colour-palettes.Rmd | 0 .../{ => articles}/cookbook/_customisations.Rmd | 0 vignettes/{ => articles}/saving.Rmd | 0 13 files changed, 8 insertions(+), 12 deletions(-) rename vignettes/{ => articles}/.gitignore (100%) rename vignettes/{ => articles}/accessibility.Rmd (100%) rename vignettes/{ => articles}/colours.Rmd (100%) rename vignettes/{ => articles}/cookbook.Rmd (100%) rename vignettes/{ => articles}/cookbook/_acknowledgments.Rmd (100%) rename vignettes/{ => articles}/cookbook/_annotations.Rmd (100%) rename vignettes/{ => articles}/cookbook/_chart-types.Rmd (100%) rename vignettes/{ => articles}/cookbook/_colour-palettes.Rmd (100%) rename vignettes/{ => articles}/cookbook/_customisations.Rmd (100%) rename vignettes/{ => articles}/saving.Rmd (100%) diff --git a/.Rbuildignore b/.Rbuildignore index 24e97c8..ed7d305 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -12,3 +12,4 @@ ^Meta$ ^cran-comments\.md$ ^CRAN-SUBMISSION$ +^vignettes/articles$ diff --git a/DESCRIPTION b/DESCRIPTION index 64cf46d..03104b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,22 +19,13 @@ Imports: lifecycle, rlang, scales -Suggests: +Suggests: dplyr, - gapminder, - glue, gt, - knitr, - plotly, - purrr, - rmarkdown, - stringr, testthat (>= 2.1.0), - tibble, - tidyr -VignetteBuilder: - knitr + tibble Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 +Config/Needs/website: rmarkdown diff --git a/NEWS.md b/NEWS.md index 5150a18..691f8f8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # sgplot (development version) +* Vignettes are converted to articles. Vignettes are now not available to view +locally and only via the +[pkgdown site](https://scotgovanalysis.github.io/sgplot/) (#66). + * Set minimum version of ggplot (>= 3.5.0) (#62). * Fix bug where `use_sgplot()` could not handle passing multiple arguments of diff --git a/vignettes/.gitignore b/vignettes/articles/.gitignore similarity index 100% rename from vignettes/.gitignore rename to vignettes/articles/.gitignore diff --git a/vignettes/accessibility.Rmd b/vignettes/articles/accessibility.Rmd similarity index 100% rename from vignettes/accessibility.Rmd rename to vignettes/articles/accessibility.Rmd diff --git a/vignettes/colours.Rmd b/vignettes/articles/colours.Rmd similarity index 100% rename from vignettes/colours.Rmd rename to vignettes/articles/colours.Rmd diff --git a/vignettes/cookbook.Rmd b/vignettes/articles/cookbook.Rmd similarity index 100% rename from vignettes/cookbook.Rmd rename to vignettes/articles/cookbook.Rmd diff --git a/vignettes/cookbook/_acknowledgments.Rmd b/vignettes/articles/cookbook/_acknowledgments.Rmd similarity index 100% rename from vignettes/cookbook/_acknowledgments.Rmd rename to vignettes/articles/cookbook/_acknowledgments.Rmd diff --git a/vignettes/cookbook/_annotations.Rmd b/vignettes/articles/cookbook/_annotations.Rmd similarity index 100% rename from vignettes/cookbook/_annotations.Rmd rename to vignettes/articles/cookbook/_annotations.Rmd diff --git a/vignettes/cookbook/_chart-types.Rmd b/vignettes/articles/cookbook/_chart-types.Rmd similarity index 100% rename from vignettes/cookbook/_chart-types.Rmd rename to vignettes/articles/cookbook/_chart-types.Rmd diff --git a/vignettes/cookbook/_colour-palettes.Rmd b/vignettes/articles/cookbook/_colour-palettes.Rmd similarity index 100% rename from vignettes/cookbook/_colour-palettes.Rmd rename to vignettes/articles/cookbook/_colour-palettes.Rmd diff --git a/vignettes/cookbook/_customisations.Rmd b/vignettes/articles/cookbook/_customisations.Rmd similarity index 100% rename from vignettes/cookbook/_customisations.Rmd rename to vignettes/articles/cookbook/_customisations.Rmd diff --git a/vignettes/saving.Rmd b/vignettes/articles/saving.Rmd similarity index 100% rename from vignettes/saving.Rmd rename to vignettes/articles/saving.Rmd From 2ffc9fe8572a8f352753b7e8d35c72e91b270830 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 31 Jul 2025 16:29:09 +0100 Subject: [PATCH 13/20] Fix broken link --- vignettes/articles/cookbook/_chart-types.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/articles/cookbook/_chart-types.Rmd b/vignettes/articles/cookbook/_chart-types.Rmd index 3630b1a..776e2e5 100644 --- a/vignettes/articles/cookbook/_chart-types.Rmd +++ b/vignettes/articles/cookbook/_chart-types.Rmd @@ -48,7 +48,7 @@ gapminder |> ) ``` -An example with line labels and no legend can be found in the [Adding annotations](#adding-annotations) section. +An example with line labels and no legend can be found in the [Annotations](#annotations) section. ## Bar charts From 064bd69e4bfdea0466b6dbf3f865ed4cf1c62720 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 31 Jul 2025 16:43:10 +0100 Subject: [PATCH 14/20] Remove size aes from scatterplot (to make chart less cluttered) --- vignettes/articles/cookbook/_chart-types.Rmd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vignettes/articles/cookbook/_chart-types.Rmd b/vignettes/articles/cookbook/_chart-types.Rmd index 776e2e5..0c9ad17 100644 --- a/vignettes/articles/cookbook/_chart-types.Rmd +++ b/vignettes/articles/cookbook/_chart-types.Rmd @@ -197,7 +197,7 @@ gapminder |> gapminder |> filter(year == 2007) |> - ggplot(aes(x = gdpPercap, y = lifeExp, size = pop)) + + ggplot(aes(x = gdpPercap, y = lifeExp)) + geom_point(colour = sg_colour_values["dark-blue"]) + theme_sg(axis = "none", grid = "xy") + scale_x_continuous( @@ -207,7 +207,6 @@ gapminder |> labs( x = "GDP", y = "Life\nExpectancy", - size = "Population", title = stringr::str_wrap( "The relationship between GDP and Life Expectancy is complex", 40 ), From 5566a3fc4c5d9c298e761c20d98b5b076775419f Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 31 Jul 2025 17:00:23 +0100 Subject: [PATCH 15/20] Remove colour from labels (use black) and adjust max label on x-axis --- vignettes/articles/cookbook/_annotations.Rmd | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/vignettes/articles/cookbook/_annotations.Rmd b/vignettes/articles/cookbook/_annotations.Rmd index 547fc44..a4c8ea6 100644 --- a/vignettes/articles/cookbook/_annotations.Rmd +++ b/vignettes/articles/cookbook/_annotations.Rmd @@ -21,13 +21,11 @@ ann_data |> breaks = seq(0, 80, 20), expand = c(0, 0)) + scale_x_continuous(limits = c(1952, 2017), - breaks = seq(1952, 2017, 5)) + + breaks = seq(1952, 2007, 5)) + annotate(geom = "label", x = 2008, y = 73, label = "China", - colour = sg_colour_values[1], label.size = NA, hjust = 0, vjust = 0.5) + annotate(geom = "label", x = 2008, y = 79.4, label = "United Kingdom", - colour = sg_colour_values[2], label.size = NA, hjust = 0, vjust = 0.5) + labs( @@ -56,17 +54,17 @@ ann_labs <- ann_data |> ungroup() ann_data |> - ggplot(aes(x = year, y = lifeExp, colour = country)) + - geom_line(linewidth = 1) + + ggplot() + + geom_line(aes(x = year, y = lifeExp, colour = country), linewidth = 1) + theme_sg(legend = "none") + scale_colour_discrete_sg() + scale_y_continuous(limits = c(0, 82), breaks = seq(0, 80, 20), expand = c(0, 0)) + scale_x_continuous(limits = c(1952, 2017), - breaks = seq(1952, 2017, 5)) + + breaks = seq(1952, 2007, 5)) + geom_label(data = ann_labs, - aes(x = year, y = lifeExp, label = country, colour = country), + aes(x = year, y = lifeExp, label = country), hjust = 0, vjust = 0.5, nudge_x = 0.5, From 036d85eb34676b9e6c4632e96a2f017024e181a9 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Fri, 1 Aug 2025 09:34:40 +0100 Subject: [PATCH 16/20] Make hline grey (instead of turquoise) and reorder layers --- vignettes/articles/cookbook/_customisations.Rmd | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vignettes/articles/cookbook/_customisations.Rmd b/vignettes/articles/cookbook/_customisations.Rmd index 0a1f082..d8dd552 100644 --- a/vignettes/articles/cookbook/_customisations.Rmd +++ b/vignettes/articles/cookbook/_customisations.Rmd @@ -111,9 +111,12 @@ To add a horizontal or vertical line across the whole plot, use `geom_hline()` o gapminder |> filter(country == "United Kingdom") |> ggplot(aes(x = year, y = lifeExp)) + - geom_line(linewidth = 1, colour = sg_colour_values[1]) + - geom_hline(yintercept = 75, colour = sg_colour_values[2], - linewidth = 1, linetype = "dashed") + + geom_hline(yintercept = 75, + colour = sg_colour_values["grey"], + linewidth = 1, + linetype = "longdash") + + geom_line(linewidth = 1, + colour = sg_colour_values["dark-blue"]) + annotate(geom = "text", x = 2007, y = 70, label = "Age 70") + theme_sg() + scale_y_continuous(limits = c(0, 82), From 19ffaadb279dad4c4682a83430bc64d0a7efa487 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Fri, 1 Aug 2025 09:41:49 +0100 Subject: [PATCH 17/20] Hyphenate x and y axis (e.g. x-axis instead of x axis) --- vignettes/articles/accessibility.Rmd | 4 ++-- vignettes/articles/cookbook/_chart-types.Rmd | 2 +- vignettes/articles/cookbook/_customisations.Rmd | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/vignettes/articles/accessibility.Rmd b/vignettes/articles/accessibility.Rmd index 709f184..c8805cf 100644 --- a/vignettes/articles/accessibility.Rmd +++ b/vignettes/articles/accessibility.Rmd @@ -39,9 +39,9 @@ By applying `theme_sg` to ggplot2 plots, the following best practice is followed * Plot background is white. -* Axis lines and ticks are light grey (#595959). By default, only the x axis is shown but these can be controlled using the `axis` and `ticks` arguments. +* Axis lines and ticks are light grey (#595959). By default, only the x-axis is shown but these can be controlled using the `axis` and `ticks` arguments. -* Grid lines are light grey (#595959) and kept to a minimum; by default only major y axis lines are shown, but this can be controlled using the `grid` argument. +* Grid lines are light grey (#595959) and kept to a minimum; by default only major y-axis lines are shown, but this can be controlled using the `grid` argument. * Text is black, uses a Sans Serif font and is size 12 by default. Text size can be controlled using the `base_size` argument. diff --git a/vignettes/articles/cookbook/_chart-types.Rmd b/vignettes/articles/cookbook/_chart-types.Rmd index 0c9ad17..2652c7a 100644 --- a/vignettes/articles/cookbook/_chart-types.Rmd +++ b/vignettes/articles/cookbook/_chart-types.Rmd @@ -80,7 +80,7 @@ ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + ) ``` -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_sg()`; 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. +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_sg()`; 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. ```{r bar-chart-2} #| fig.alt = "A horizontal bar chart using sgplot theme and dark blue colour." diff --git a/vignettes/articles/cookbook/_customisations.Rmd b/vignettes/articles/cookbook/_customisations.Rmd index d8dd552..56c75fa 100644 --- a/vignettes/articles/cookbook/_customisations.Rmd +++ b/vignettes/articles/cookbook/_customisations.Rmd @@ -41,12 +41,12 @@ last_plot() + By default, a bar chart will have a gap between the bottom of the bars and the axis. This can be removed as follows: ```{r expand} -#| fig.alt = "A bar chart with no space between bottom of bars and x axis." +#| fig.alt = "A bar chart with no space between bottom of bars and x-axis." last_plot() + scale_x_continuous(expand = c(0, 0)) ``` -The equivalent adjustment can be made for the y axis using `scale_y_continuous`. +The equivalent adjustment can be made for the y-axis using `scale_y_continuous`. ### Changing axis limits, breaks and labels @@ -54,7 +54,7 @@ The equivalent adjustment can be made for the y axis using `scale_y_continuous`. Axis limits, breaks and labels for continuous variables can be controlled using `scale_x/y_continuous()`. For discrete variables, labels can be changed using `scale_x/y_discrete()` or alternatively by recoding the variable in the data before creating a chart. ```{r axis-limits-breaks-labels} -#| fig.alt = "A bar chart with fewer x axis breaks and edited labels." +#| fig.alt = "A bar chart with fewer x-axis breaks and edited labels." last_plot() + scale_x_continuous(expand = c(0, 0), @@ -68,10 +68,10 @@ Note that further calls to `scale_x/y_continuous` will overwrite previous calls, ### Formatting labels -Formatting axis labels or legend labels is easily handled using the `scales` package. The following example formats y axis labels as percentages, however `scales` can also handle currency and thousands separators. +Formatting axis labels or legend labels is easily handled using the `scales` package. The following example formats y-axis labels as percentages, however `scales` can also handle currency and thousands separators. ```{r using-scales, fig.height = 5.5} -#| fig.alt = "A stacked bar chart with y axis labels formatted as percentages." +#| fig.alt = "A stacked bar chart with y-axis labels formatted as percentages." stacked_bar_data |> ggplot(aes(x = continent, y = n_countries, fill = lifeExpGrouped)) + @@ -92,7 +92,7 @@ stacked_bar_data |> ### Avoiding axis/grid lines being cut off -Axis lines and grid lines can sometimes appear 'cut off' if they are drawn at the limits of the chart range. You can see in the example in the previous section that the top grid line is slightly narrower than the adjacent tick mark on the y axis. This is because the y axis limit is 100%. As the grid line is centred at 100%, the top half of the line is 'cut off'. This can be corrected as follows: +Axis lines and grid lines can sometimes appear 'cut off' if they are drawn at the limits of the chart range. You can see in the example in the previous section that the top grid line is slightly narrower than the adjacent tick mark on the y-axis. This is because the y-axis limit is 100%. As the grid line is centred at 100%, the top half of the line is 'cut off'. This can be corrected as follows: ```{r clip, fig.height = 5.5} #| fig.alt = "A stacked bar chart with top gridline the same width as adjoining tick mark and other grid lines." @@ -138,7 +138,7 @@ gapminder |> If text is too long, it may be cut off or distort the dimensions of the chart. ```{r text-wrap-1} -#| fig.alt = "A bar chart with end of main title text not visible and long y axis title skewing the dimensions of the chart." +#| fig.alt = "A bar chart with end of main title text not visible and long y-axis title skewing the dimensions of the chart." plot <- ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + @@ -165,7 +165,7 @@ plot + There are two suggested ways to solve this issue; Insert `\n` within a string to force a line break; Use `stringr::str_wrap()` to set a maximum character width of the string. See examples of both of these methods as follows: ```{r text-wrap-2} -#| fig.alt = "A bar chart with main title and y axis title text wrapped onto two lines." +#| fig.alt = "A bar chart with main title and y-axis title text wrapped onto two lines." plot + labs( From 1d552193b9b68b36e3180cdec90c06eb3787359b Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Fri, 1 Aug 2025 12:24:07 +0100 Subject: [PATCH 18/20] Move legend to right (to ensure order of legend matches order of stacks) --- vignettes/articles/cookbook/_chart-types.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/articles/cookbook/_chart-types.Rmd b/vignettes/articles/cookbook/_chart-types.Rmd index 2652c7a..2f740b0 100644 --- a/vignettes/articles/cookbook/_chart-types.Rmd +++ b/vignettes/articles/cookbook/_chart-types.Rmd @@ -152,7 +152,7 @@ stacked_bar_data <- ggplot(stacked_bar_data, aes(x = continent, y = n_countries, fill = lifeExpGrouped)) + geom_bar(stat = "identity", position = "fill") + - theme_sg(legend = "bottom") + + theme_sg(legend = "right") + scale_y_continuous(expand = c(0, 0), labels = scales::percent) + coord_cartesian(clip = "off") + scale_fill_discrete_sg() + From 2ea80461465144e1638fb98be6e7713c24c30fbe Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Fri, 1 Aug 2025 17:30:09 +0100 Subject: [PATCH 19/20] Refine and reorder customisations content --- .../articles/cookbook/_customisations.Rmd | 180 +++++++++--------- 1 file changed, 87 insertions(+), 93 deletions(-) diff --git a/vignettes/articles/cookbook/_customisations.Rmd b/vignettes/articles/cookbook/_customisations.Rmd index 56c75fa..89d6a6d 100644 --- a/vignettes/articles/cookbook/_customisations.Rmd +++ b/vignettes/articles/cookbook/_customisations.Rmd @@ -1,13 +1,27 @@ ## Other customisations -`theme_sg()` has arguments to control the legend position and appearance of grid lines, axis lines and axis ticks. More information on accepted values can be found in the [help file](https://scotgovanalysis.github.io/sgplot/reference/theme_sg.html). +The following section demonstrates some common customisations made to `{ggplot2}` charts. Each example builds on the previous one. + +Note that `theme_sg()` has arguments to control the legend position and appearance of grid lines, axis lines and axis ticks. More information on accepted values can be found in the [help file](https://scotgovanalysis.github.io/sgplot/reference/theme_sg.html). + +Customisations will be made to the following basic horizontal bar chart: + +```{r before-customisation} +#| fig.alt = "A horizontal bar chart using sgplot theme and dark blue colour." + +bar_data |> + ggplot(aes(x = pop, y = country)) + + geom_col(fill = sg_colour_values["dark-blue"]) + + theme_sg(axis = "y", grid = "x") +``` + ### Sorting a bar chart To control the order of bars in a chart, wrap the variable you want to arrange with `reorder()` and specify what variable you want to sort by. The following example sorts bars in ascending order of life expectancy. To sort in descending order, you would change this to `reorder(country, desc(lifeExp))`. ```{r sorting} -#| fig.alt = "A bar chart using sgplot theme and dark blue colour with bars sorted in decreasing order by life expectancy." +#| fig.alt = "A horizontal bar chart using sgplot theme and dark blue colour with bars sorted in decreasing order by population." bar_data |> ggplot(aes(x = pop, y = reorder(country, pop))) + @@ -15,26 +29,53 @@ bar_data |> theme_sg(axis = "y", grid = "x") ``` -Examples in the following sections build on this chart. - -### Changing chart titles +### Changing chart titles and wrapping text Chart titles such as the main title, subtitle, caption, axis titles and legend titles, can be controlled using `labs()`. A title can be removed using `NULL`. +Remember that it is [best practice to provide chart titles and subtitles in the main body of text](https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-charts/#section-5), rather than embedded in the chart. + ```{r chart-titles} -#| fig.alt = "A bar chart with title, subtitle and caption. Axis titles have been removed." +#| fig.alt = "A bar chart with title, subtitle and caption. The axis titles have been removed. The main title is too long and the end is cut off." last_plot() + labs( x = NULL, y = NULL, - title = "The United States is the most populous country \nin the Americas", + title = "The United States is the most populous country in the Americas", subtitle = "Population of countries in the Americas (millions), 2007", caption = "Source: Gapminder" ) ``` +If text is too long, it may be cut off or distort the dimensions of the chart. There are two suggested ways to solve this issue. + +Insert `\n` within a string to force a line break: + +```{r text-wrap-1} +#| fig.alt = "A bar chart with main title and y-axis title text wrapped onto two lines." + +last_plot() + + labs( + title = "The United States is the most populous country \nin the Americas" + ) +``` + +Use `stringr::str_wrap()` to set a maximum character width of the string: + +```{r text-wrap-2} +#| fig.alt = "A bar chart with main title and y-axis title text wrapped onto two lines." + +last_plot() + + labs( + title = stringr::str_wrap( + "The United States is the most populous country in the Americas", + width = 50 + ) + ) +``` + ### Reducing space between chart and axis @@ -43,7 +84,8 @@ By default, a bar chart will have a gap between the bottom of the bars and the a ```{r expand} #| fig.alt = "A bar chart with no space between bottom of bars and x-axis." -last_plot() + scale_x_continuous(expand = c(0, 0)) +last_plot() + + scale_x_continuous(expand = c(0, 0)) ``` The equivalent adjustment can be made for the y-axis using `scale_y_continuous`. @@ -53,8 +95,10 @@ The equivalent adjustment can be made for the y-axis using `scale_y_continuous`. Axis limits, breaks and labels for continuous variables can be controlled using `scale_x/y_continuous()`. For discrete variables, labels can be changed using `scale_x/y_discrete()` or alternatively by recoding the variable in the data before creating a chart. +Note that further calls to `scale_x/y_continuous` will overwrite previous calls, hence why `expand = c(0, 0)` has been included again in these examples. + ```{r axis-limits-breaks-labels} -#| fig.alt = "A bar chart with fewer x-axis breaks and edited labels." +#| fig.alt = "A bar chart with more x-axis breaks and formatted labels. The last label is suffixed with 'million'." last_plot() + scale_x_continuous(expand = c(0, 0), @@ -63,15 +107,38 @@ last_plot() + labels = c(seq(0, 250, 50), "300 million")) ``` -Note that further calls to `scale_x/y_continuous` will overwrite previous calls, hence why `expand = c(0, 0)` has been included again in this example. +Labels can also be formatted using a function. The `{scales}` package provides many convenient functions for this, and can handle percentages, currency and thousands separators. + +```{r scales-pkg} +#| fig.alt = "A bar chart with fewer x-axis breaks and labels formatted with comma thousands separators." + +last_plot() + + scale_x_continuous(expand = c(0, 0), + limits = c(0, 3e8 * 1.1), + breaks = seq(0, 3e8, 1e8), + labels = scales::label_comma()) +``` + + +### Adjusting theme elements + +If you find you need to adjust theme elements for your chart, this can be done using `theme()`. Note that this should be done after the call to `theme_sg()`, otherwise `theme_sg()` may overwrite the specifications you've made. + +```{r adjust-theme} +#| fig.alt = "A bar chart using sgplot theme and dark blue colour, with y-axis lines and ticks coloured black." + +last_plot() + + theme(axis.line.y = element_line(colour = "black"), + axis.ticks.y = element_line(colour = "black")) +``` -### Formatting labels +### Avoiding axis/grid lines being cut off -Formatting axis labels or legend labels is easily handled using the `scales` package. The following example formats y-axis labels as percentages, however `scales` can also handle currency and thousands separators. +Axis lines and grid lines can sometimes appear 'cut off' if they are drawn at the limits of the chart range. You can see in the following example that the top grid line is slightly narrower than the adjacent tick mark on the y-axis. This is because the y-axis limit is 100%. As the grid line is centred at 100%, the top half of the line is 'cut off'. -```{r using-scales, fig.height = 5.5} -#| fig.alt = "A stacked bar chart with y-axis labels formatted as percentages." +```{r clip-1, fig.height = 5.5} +#| fig.alt = "A stacked bar chart with top gridline is half the width of the adjoining tick mark and other grid lines." stacked_bar_data |> ggplot(aes(x = continent, y = n_countries, fill = lifeExpGrouped)) + @@ -89,24 +156,22 @@ stacked_bar_data |> ) ``` +This can be corrected as follows: -### Avoiding axis/grid lines being cut off - -Axis lines and grid lines can sometimes appear 'cut off' if they are drawn at the limits of the chart range. You can see in the example in the previous section that the top grid line is slightly narrower than the adjacent tick mark on the y-axis. This is because the y-axis limit is 100%. As the grid line is centred at 100%, the top half of the line is 'cut off'. This can be corrected as follows: - -```{r clip, fig.height = 5.5} +```{r clip-2, fig.height = 5.5} #| fig.alt = "A stacked bar chart with top gridline the same width as adjoining tick mark and other grid lines." -last_plot() + coord_cartesian(clip = "off") +last_plot() + + coord_cartesian(clip = "off") ``` -### Adding a line +### Adding a reference line To add a horizontal or vertical line across the whole plot, use `geom_hline()` or `geom_vline()`. This can be useful to highlight a threshold or average level. ```{r add-a-line} -#| fig.alt = "A line chart with dashed, orange horizontal line at age 75." +#| fig.alt = "A line chart with dashed, grey horizontal line at age 75." gapminder |> filter(country == "United Kingdom") |> @@ -132,74 +197,3 @@ gapminder |> ) ``` - -### Wrapping text - -If text is too long, it may be cut off or distort the dimensions of the chart. - -```{r text-wrap-1} -#| fig.alt = "A bar chart with end of main title text not visible and long y-axis title skewing the dimensions of the chart." - -plot <- - ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + - geom_col(fill = sg_colour_values["dark-blue"]) + - theme_sg() + - scale_y_continuous( - labels = \(x) x / 1e6, - limits = c(0, 3e8 * 1.02), - expand = c(0, 0) - ) + - labs( - x = NULL, - subtitle = "Population of countries in the Americas, 2007", - caption = "Source: Gapminder" - ) - -plot + - labs( - y = "Population (millions)", - title = "The United States is the most populous country in the Americas", - ) -``` - -There are two suggested ways to solve this issue; Insert `\n` within a string to force a line break; Use `stringr::str_wrap()` to set a maximum character width of the string. See examples of both of these methods as follows: - -```{r text-wrap-2} -#| fig.alt = "A bar chart with main title and y-axis title text wrapped onto two lines." - -plot + - labs( - y = "Population\n(millions)", - title = stringr::str_wrap( - "The United States is the most populous country in the Americas", - width = 50 - ) - ) -``` - - -### Adjusting theme elements - -If you find you need to adjust theme elements for your chart, this can be done using `theme()`. Note that this should be done after the call to `theme_sg()`, otherwise `theme_sg()` may overwrite the specifications you've made. - -```{r adjust-theme} -#| fig.alt = "A bar chart using sgplot theme and dark blue colour, with axis lines and ticks coloured black." - -ggplot(bar_data, aes(x = reorder(country, -pop), y = pop)) + - geom_col(fill = sg_colour_values["dark-blue"]) + - theme_sg(axis = "xy") + - theme(axis.line = element_line(colour = "black"), - axis.ticks = element_line(colour = "black")) + - scale_y_continuous( - labels = \(x) x / 1e6, - limits = c(0, 3e8 * 1.02), - expand = c(0, 0) - ) + - labs( - x = NULL, - y = NULL, - title = "The United States is the most populous country \nin the Americas", - subtitle = "Population of countries in the Americas (millions), 2007", - caption = "Source: Gapminder" - ) -``` From 703b2a3dfad7ee5df0a4c8b796b24e445e736755 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Fri, 1 Aug 2025 17:42:33 +0100 Subject: [PATCH 20/20] Use relative links within pkgdown site (closes #43) --- vignettes/articles/colours.Rmd | 10 +++++----- vignettes/articles/cookbook.Rmd | 2 +- vignettes/articles/cookbook/_colour-palettes.Rmd | 8 ++++---- vignettes/articles/cookbook/_customisations.Rmd | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/vignettes/articles/colours.Rmd b/vignettes/articles/colours.Rmd index 7e22a29..4c50bb4 100644 --- a/vignettes/articles/colours.Rmd +++ b/vignettes/articles/colours.Rmd @@ -106,7 +106,7 @@ The `grey` in this palette does not meet the required colour contrast with an of ### Social Security Scotland {#sss} -To use a Social Security Scotland palette, set `palette_type = "sss"` when using any of the `scale_` [colour functions](https://scotgovanalysis.github.io/sgplot/reference/index.html#colour-scales). +To use a Social Security Scotland palette, set `palette_type = "sss"` when using any of the `scale_` [colour functions](../reference/index.html#colour-scales). If you have any questions about these palettes, please contact the [Social Security Scotland statistics mailbox](mailto:MI@socialsecurity.gov.scot). @@ -157,7 +157,7 @@ sgplot:::colour_table(sgplot::sss_colour_palettes$focus) ### Government Analysis Function {#af} -The Government Analysis Function guidance also contains [suggested colour palettes](https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-colours-in-charts/#section-4). These are also provided in sgplot, however the Scottish Government palettes are used by default. To use an Analysis Function palette, set `palette_type = "af"` when using any of the `scale_` [colour functions](https://scotgovanalysis.github.io/sgplot/reference/index.html#colour-scales). +The Government Analysis Function guidance also contains [suggested colour palettes](https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-colours-in-charts/#section-4). These are also provided in sgplot, however the Scottish Government palettes are used by default. To use an Analysis Function palette, set `palette_type = "af"` when using any of the `scale_` [colour functions](../reference/index.html#colour-scales). #### Main palette @@ -224,8 +224,8 @@ There may be instances where you'd like to use a different colour palette. If so, this should be carefully considered to ensure it meets accessibility requirements. The Analysis Function guidance outlines [appropriate steps for choosing your own accessible colour palette](https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-colours-in-charts/#section-9) and should be used. -An example of how to use an alternative colour palette is provided in the [cookbook](https://scotgovanalysis.github.io/sgplot/articles/cookbook.html#using-your-own-colour-palette). -However, if you use a different palette regularly and feel it would be useful for this to be added to sgplot, please make a suggestion as per the [contributing guidance](https://scotgovanalysis.github.io/sgplot/CONTRIBUTING.html). +An example of how to use an alternative colour palette is provided in the [cookbook](cookbook.html#using-your-own-colour-palette). +However, if you use a different palette regularly and feel it would be useful for this to be added to sgplot, please make a suggestion as per the [contributing guidance](../CONTRIBUTING.html). ## Viewing palettes in R @@ -249,4 +249,4 @@ sgplot::sss_colour_palettes sgplot::af_colour_palettes ``` -Examples of how to apply these palettes to ggplot2 charts are available in both the [cookbook](https://scotgovanalysis.github.io/sgplot/articles/cookbook.html) and the reference files for `scale_` [colour functions](https://scotgovanalysis.github.io/sgplot/reference/index.html#colour-scales). +Examples of how to apply these palettes to ggplot2 charts are available in both the [cookbook](cookbook.html) and the reference files for `scale_` [colour functions](../reference/index.html#colour-scales). diff --git a/vignettes/articles/cookbook.Rmd b/vignettes/articles/cookbook.Rmd index 2bb5c08..f4dbd4c 100644 --- a/vignettes/articles/cookbook.Rmd +++ b/vignettes/articles/cookbook.Rmd @@ -43,7 +43,7 @@ Titles, subtitles and captions have been embedded in the charts in this cookbook ### use_sgplot -The examples in this cookbook use the sgplot theme and colour functions explicitly, however it may be easier to make use of the `use_sgplot()` function if your charts all require a similar style. More information on `use_sgplot` can be found on the [sgplot homepage](https://scotgovanalysis.github.io/sgplot/#use-sgplot-as-default). +The examples in this cookbook use the sgplot theme and colour functions explicitly, however it may be easier to make use of the `use_sgplot()` function if your charts all require a similar style. More information on `use_sgplot` can be found on the [sgplot homepage](../index.html#use-sgplot-as-default). ```{r chart-types, child = "cookbook/_chart-types.Rmd"} diff --git a/vignettes/articles/cookbook/_colour-palettes.Rmd b/vignettes/articles/cookbook/_colour-palettes.Rmd index 6f81c52..73a948e 100644 --- a/vignettes/articles/cookbook/_colour-palettes.Rmd +++ b/vignettes/articles/cookbook/_colour-palettes.Rmd @@ -3,9 +3,9 @@ sgplot provides colour palettes as set out by the [Scottish Government Design System](https://designsystem.gov.scot/guidance/charts/data-visualisation-colour-palettes). These palettes have been developed to meet the [Web Content Accessibility Guidelines 2.1 for graphical objects](https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html). -The [main palette](https://scotgovanalysis.github.io/sgplot/articles/colours.html#sg-main) is the default for discrete colour/fill functions, and the [sequential palette](https://scotgovanalysis.github.io/sgplot/articles/colours.html#sg-sequential) for continuous colour/fill functions. +The [main palette](colours.html#sg-main) is the default for discrete colour/fill functions, and the [sequential palette](colours.html#sg-sequential) for continuous colour/fill functions. -The Scottish Government palettes are used by default, however palettes are also available for [Social Security Scotland](https://scotgovanalysis.github.io/sgplot/articles/colours.html#sss) and the [Government Analysis Function](https://scotgovanalysis.github.io/sgplot/articles/colours.html#af). +The Scottish Government palettes are used by default, however palettes are also available for [Social Security Scotland](colours.html#sss) and the [Government Analysis Function](colours.html#af). More information on the colours used in sgplot can be found at `vignette("colours")`. @@ -43,7 +43,7 @@ gapminder |> Note: This chart is for demonstration purposes only. Accessibility guidance recommends using a maximum of four colours to avoid clutter. -To use an Analysis Function palette, set `palette_type = "af"` when using any of the `scale_` [colour functions](https://scotgovanalysis.github.io/sgplot/reference/index.html#colour-scales). +To use an Analysis Function palette, set `palette_type = "af"` when using any of the `scale_` [colour functions](../reference/index.html#colour-scales). For example, to use the Analysis Function `main2` palette: ```{r af-palette, fig.height = 5} @@ -125,4 +125,4 @@ gapminder |> #### Adding a new colour palette to sgplot -If you use a different palette regularly and feel it would be useful for this to be added to sgplot, please make a suggestion as per the [contributing guidance](https://scotgovanalysis.github.io/sgplot/CONTRIBUTING.html). +If you use a different palette regularly and feel it would be useful for this to be added to sgplot, please make a suggestion as per the [contributing guidance](../CONTRIBUTING.html). diff --git a/vignettes/articles/cookbook/_customisations.Rmd b/vignettes/articles/cookbook/_customisations.Rmd index 89d6a6d..fb6a750 100644 --- a/vignettes/articles/cookbook/_customisations.Rmd +++ b/vignettes/articles/cookbook/_customisations.Rmd @@ -2,7 +2,7 @@ The following section demonstrates some common customisations made to `{ggplot2}` charts. Each example builds on the previous one. -Note that `theme_sg()` has arguments to control the legend position and appearance of grid lines, axis lines and axis ticks. More information on accepted values can be found in the [help file](https://scotgovanalysis.github.io/sgplot/reference/theme_sg.html). +Note that `theme_sg()` has arguments to control the legend position and appearance of grid lines, axis lines and axis ticks. More information on accepted values can be found in the [help file](../reference/theme_sg.html). Customisations will be made to the following basic horizontal bar chart: