Using Code to Automatically Style Charts for Publications

Post by Joe & Aron, Data Science Unit, Welsh Government

Darllenwch y dudalen hon yn Gymraeg

Welsh Government staff in the Knowledge and Analytical Services (KAS) spend many hours formatting their charts for publication, making sure font sizes are correct, colours follow the guidance and axes are labelled. The Data Science Unit has streamlined these processes by creating a code package written in R, known as “KASStylesR”. With KASStylesR, teams can produce publication-ready Welsh and English charts in a fraction of the time it would have taken before.

1000s of charts a year – lots of time savings to be made!

The Welsh Government publishes a large volume of research and statistical reports online across a range of areas including economics, education, and health statistics. Statisticians, analysts, and researchers develop these to ensure independent and useful data are widely available. Charts are often used to illustrate the data and provide further context in an understandable and accessible way.

KASStylesR applies a colour scheme, styling, and helps users to formalise and save charts. These features replace time-consuming manual processing. In one case, KASStylesR helped a statistician reduce their processing time in a publication from one and a half days to under an hour! The total amount of time saving will only increase as more people in the Welsh Government adopt KASStylesR.

Helping users to follow best practice and ensuring accessibility

KASStylesR also helps us produce accessible content.  For example, if someone chooses to use a chart with 6 distinct colours, a warning message advises that a more digestible chart format is needed. When saving charts for publication, KASStylesR also prompts us to add in relevant information.

KASStylesR is just one way in which the Data Science Unit is encouraging the use of Reproducible Analytical Pipelines (RAP) in Welsh Government. RAP replaces manual data processing tasks with a coded process, written in programming languages like Python and R. RAP can save time, make improvements and increase quality through reproducibility, transparency, automated error-checking, and avoiding manual errors.

Sounds like it might help you? You can use it too!

The published version of the tool can be accessed here: wgdsu/KASStylesR (github.com). This means new suggestions and features will be available for all users, and new guidance only needs to be implemented once to the benefit of everyone. By making it available for all, other organisations can also adopt the code, adapt it to their needs, and use it for their own publications.


Leave a comment