Data Journalism with R
0.1 About this book
This is a practical introduction to data journalism using R. It is designed for students at any level, practitioners, and professional journalists who want to use data in their reporting. No previous programming experience is required.
Data journalism is a skill, and the best way to learn it is by doing. The book starts with small R tasks, then gradually moves toward cleaning data, finding patterns, making charts, and developing evidence for a story.
Learning these foundations also helps you evaluate work produced with AI. A tool may generate code quickly, but a journalist still needs to understand the data, check the calculation, and decide whether the evidence supports the claim.
R often provides more than one valid function for the same general task. Some functions are included with R itself; these are commonly called base R. Others come from packages, including the tidyverse collection.
This book uses a tidyverse-first workflow so beginners can learn one consistent style. When both approaches are available, the main examples usually use the tidyverse function—for example, read_csv() instead of read.csv() and parse_double() instead of as.double() for imported text. The base R alternative may be mentioned so that you can recognize it in other code.
This does not mean base R is incorrect or forbidden. We still use simple base R functions such as c(), sum(), mean(), and is.na() when they are the clearest tools for the task. Different valid code can produce the same result; the important questions are whether the code is understandable, reproducible, and appropriate for the data.
0.2 What you will learn
- R fundamentals: objects, functions, tables, and code that can be rerun;
- Data import and cleaning: bring CSV files into R and prepare them with the tidyverse;
- Data analysis: calculate summaries, comparisons, rankings, and trends;
- Data visualization: create clear charts and maps with
ggplot2; and - Data storytelling: connect a reporting question to evidence, context, and limitations.
0.3 Structure of the book
The book follows five progressive parts:
- Getting Started — set up R, RStudio, an RStudio Project, and R Markdown.
- Data Import & Cleaning — import, inspect, and clean data.
- Data Analysis — calculate summaries, rankings, and comparisons; combine tables; and investigate changes over time.
- Data Visualization — explore the data and communicate a finding.
- Case Studies — apply the workflow to several real reporting topics.
The appendices contain useful links, optional publishing guidance, debugging help, and a final-project guide with examples from previous students.
In Chapter 1, create one RStudio Project named djr with a simple data folder and an outputs folder. Keep using that project as you progress through the book. Each chapter tells you which R Markdown notebook to create, which file to download, and which earlier files to reuse.
0.4 The main dataset
Most core chapters use the year-end equity holdings of Norway’s Government Pension Fund Global, published by Norges Bank Investment Management (NBIM). The data include companies, markets, industries, market values, and ownership information. We begin with one year and introduce multiple years only after the basic workflow is familiar.
The original source is the NBIM all-investments database. The teaching files and their data dictionary are in the repository’s data folder.
0.5 Who should read this book?
This book is for:
- students learning data journalism;
- journalists who want to add R to their reporting toolkit;
- practitioners who work with public or institutional data; and
- anyone who has a journalism question and wants to investigate it with data.
This is not a computer science textbook. It concentrates on the R and tidyverse skills that are useful for reporting.
0.6 Prerequisites
You need a computer, R, and RStudio. Chapter 1 covers the setup. Curiosity and patience are more important than previous coding experience.
0.7 How to use this book
- Work in order if you are new to R. Later chapters reuse functions taught earlier.
- Type the examples yourself. Small typing mistakes are part of learning how R works.
- Run one code chunk at a time. Look at the result before moving forward.
- Change one thing and run it again. This is often the fastest way to understand a function.
- Use the Takeaways tables. They provide a quick reference after each chapter.
0.9 Acknowledgements
This book is inspired by Reporting with Data in R by Christian McDonald and Josephine Lukito. I thank them for making their teaching materials publicly available.
This book is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.