knitr::opts_chunk$set(echo = TRUE) # this is for rendering custom fonts in markdown # but it doesn;t appear to be working ... ragg_png_wrapper = function(..., res = 150) { ragg::agg_png(..., res = res, units = "in") } knitr::opts_chunk$set(dev = ragg_png_wrapper)
library(tidyverse) library(ggtext) # improved text rendering for ggplot2 library(ggforce) # extra functionality for ggplot2 inc. improved annotation library(patchwork) # composing layouts with multiple plots library(ggdist) # visualising uncertainty and distributions library(readxl) # for reading Excel files library(lubridate) # for dates library(readxl) # for reading excel files # packages for using custom fonts # library(systemfonts) # library(textshaping) library(ragg) library(cjmr) # my own package including default styling for plots # set default theme for exploratory plots theme_set(theme_light())
A short and general reference to common tasks at the BBC: https://bbc.github.io/rcookbook/
ggplot2 wizardry by Cédric Scherer - https://z3tt.github.io/OutlierConf2021/
R Graphics Cookbook by W. Chang - https://r-graphics.org/
Custom fonts - https://yjunechoe.github.io/posts/2021-06-24-setting-up-and-debugging-custom-fonts/
Changing the size of a legend - Cédric Scherer
guides(color = guide_colorbar(title.position = "top", title.hjust = .5, barwidth = unit(20, "lines"), barheight = unit(.5, "lines")))
Changing margins - Cédric Scherer
theme(plot.margin = margin(t = 25, r = 25, b = 10, l = 25)) # top, right, bottom, left
Adjusting axis
scale_y_continuous(breaks = seq(0,350, 50), # labels limits = c(0, 350)) # extent of axis
Saving using custom fonts with ragg
ggplot(mtcars, aes(hp, mpg)) + geom_point() + labs(title = "22222222222222222") + theme(text = element_text(family = "Roboto"), plot.title = element_text(size = 50)) ggsave("filename.png", device = ragg::agg_png())
Who collected the data?
Why was the data collected?
What is the data used for?
Are there some other datasets that might be useful for comparisons?
| To think about | Notes | |-----------------------------------------------------------------------------------|-------| | Can you think of a group of people who might view the visualisations? | | | Can you think of a specific person who might view the visualizations? | | | What do want the audience to know or be able to after viewing the visualizations? | | | What expectations might the audience have about visualisations of this data? | |
...
...
Based on the questions above, the story might go something like this:
...
...
| Question | Answer (i.e. title) | Notes to consider in design, chart types etc. | |----------|---------------------|-----------------------------------------------| | | | |
| Question | Answer (i.e. title) | Notes to consider in design, chart types etc. | |----------|---------------------|-----------------------------------------------| | | | |
| Question | Answer (i.e. title) | Notes to consider in design, chart types etc. | |----------|---------------------|-----------------------------------------------| | | | |
Some useful image sizes (mm unless stated)
| Purpose | Width | Height | |-------------------------|-------|--------| | Single plot for Twitter | | | | | | | | | | |
file_folder <- "" file_name <- "holding_name" ggsave(str_c(file_folder, file_name, ".svg")) # if saving as a pdf use device = cairo_pdf in ggsave
Based on Flowing Data.
Think about each issue (in bold below) as a continuum rather than a check-box.
+-----------------------------------------------------+--------------------------------------------------------------+-------+ | Question to consider | Tips | Notes | +=====================================================+==============================================================+=======+ | Are the encodings explained? | Air on the side of too much explanation ... | | +-----------------------------------------------------+--------------------------------------------------------------+-------+ | Is the context explained? | Titles, subtitles | | | | | | | | Annotate | | | | | | | | Use colour to highlight | | +-----------------------------------------------------+--------------------------------------------------------------+-------+ | Does it have readability like text? | Think visual hierarchy (as when laying out text) | | +-----------------------------------------------------+--------------------------------------------------------------+-------+ | Do the aesthetics align with the topic/message? | Serious topic -> dark colours, straight-forward chart types | | +-----------------------------------------------------+--------------------------------------------------------------+-------+
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.