0% found this document useful (0 votes)
40 views14 pages

Visualize Change With Time in R Ggplot2 - Medium

Uploaded by

tataxp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views14 pages

Visualize Change With Time in R Ggplot2 - Medium

Uploaded by

tataxp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Get unlimited access to the best of Medium for less than $1/week.

Become a member

Awesome Strategies to Visualize


Change with Time
Bo Yuan, Ph.D. · Follow
5 min read · May 8, 2024

924 6

This article summarizes effective strategies to visualize temporal changes,


illustrated with inspiring graphic examples (with link to source code).
You can find more interesting data visualizations at DataBrewer.co, an
excellent platform that shares data analysis and data viz. skills in R and
Python.

Use Line Segments to Contrast Two Time Points


The following graph compares 1800 and 2015 regarding human life
expectancy, population size, and GDP per capita for each country. The points
signify the specific time points of different countries, and the line segments
provide a visual trajectory of the change in each country. Additionally, the
use of light grey rectangles serves to underscore the distinction between the
two time periods.

Image reproduced in R ggplot2 from work by Datawrapper.


This graph was originally created by Lisa Charlotte Rost with Datawrapper.
Check here to find my R ggplot2 reproduction of this work.

Use Arrows to Emphasize Direction of Changes


In addition to line segments, arrows are telltale elements that highlight
direction of changes from one time point to another. The graph below
employs this strategy to show the changes of seats held by women in
national parliaments from 2000 to 2020.

Image reproduced in R ggplot2 (see code) from work by Datawrapper.


Use Lines to Depict Continuous Changes
Lines are intuitive indicators of continuous changes recorded by a string of
data points. The following plot shows the dynamics of smoking popularity in
major western countries from 1880s to 2000s, and spotlighted such changes
in United States, Germany and France in bright colors.

Image reproduced in R ggplot2 (see code) from work by Datawrapper.

On top of tracing temporal changes in each individual country, the average


trend lines and variability ribbons can be added to enrich the graphic
information. In the following plot, each thin line tracks the changes in
human life expectancy in each country. On a continent-wise basis, a central
thick line shows the average life span, and the shaded ribbon represents the
variability around this average trend, showing one standard deviation above
and below the mean.
Image by author, produced in R ggplot2 (see code)

Use Ribbons to Illustrate Total Values at Each Time Point


The above line plots have shown dynamic changes for each individual
country. When the cumulative sum of y-values at each time point is of
interest, the area plot is ready to achieve this goal. Area plots are essentially
stacked line plots, with filled colors between lines to form continuous bands
or ribbons.

The following plot shows the dynamics of migration population from


worldwide to the U.S. in the past two hundred years. It shows both country-
wise and total population number at each time point.
Image reproduced in R ggplot2 (see code) from work by Datawrapper

The above graph was originally created by Mirko Lorenz with Datawrapper.
You can find here a reproduction of this work in R ggplot2 using the beautiful
ggalluvial package.

A variant of the area / alluvium plot is the stream plot, which gives an extra
touch of aesthetic enhancement. The following plot shows the changing
popularity of movie genres in the Open
pastinfour
app
decades. Check this article to find
details of its creation using the wonderful R ggstream package by David
Sjoberg. Search Write
Image adapted from the work of David Sjoberg

Use Heatmap to Present Temporal Changes


Heatmaps are another powerful tool with an engaging appeal to show
temporal changes, and maps numeric values to a color scale. The following
plot visualizes the yearly incidences of eight infectious diseases across the
U.S. states before and after the introduction of vaccines. It impressively
highlights the power of vaccination in the control of disease spread.
Image by author, inspired from the original work in WSJ

The plots were originally published by Tynan DeBold and Dov Friedman in
WSJ. Check here to see a reproduction of this work in R ggplot2.

While colors effectively reflect the overall trend of changes, they are not as
easily interpreted for precise numeric values when compared to a simple y-
axis. It can be helpful to augment a heatmap with an axis in one way or
another. The following heatmap displays monthly sunspot activities
spanning across the past two hundred years. Adjacent to the heatmap, a
synchronized line plot illustrates the continuous changes in sunspot activity
along the y-axis, facilitating a more straightforward interpretation of
fluctuations in the sunspot activities.
Image by author, produced in R ggplot2 (see code)

Visualize Changes in Animation


Data animation was made famous back in 2007 by Hans Rosling in his
legendary TED talk the best stats you’ve ever seen. Yet even today to render data
to animation appears an appalling task to many data analysts — but it does
not have to be! With the awesome R gganimate package, rendering a static
plot into animation can be as simple as adding an extra single line of code
“faceting” the dataset based on a time variable.

The following animated population pyramids show the human population


structures in Germany in the past (in dark colors) and in the future with
simulated data (in bright colors). Check here to find a detailed instruction
how to create this animation using R ggplot2.

Animation by author, data from Federal Statistical Office of Germany

I created all graphics demonstrated above in R ggplot2, a game-changing tool


in the field of visualization and data science. If you want to learn ggplot2 in a
systematic and fun way, I encourage you to check out my distinct comic-style
ebook on ggplot2. You’ll be fascinated how fast you can turn your learning
from my book into your own stunning visuals!
Data Visualization Ggplot2 Time Series Analysis R Programming

Data Science

Written by Bo Yuan, Ph.D. Follow

442 Followers

Postdoctoral Fellow at Harvard University | Analytical chemist | Physiologist | Data


scientist | Co-founder of DataBrewer.co.

More from Bo Yuan, Ph.D.

Bo Yuan, Ph.D. Bo Yuan, Ph.D.

Create a Heatmap in R ggplot2 to Create Elegant Animation of


Visualize the Control of Polio… Population Pyramids with ggplot…
In this article, we’ll use R ggplot2 to create a In this article, we’ll animate the annual
heatmap to visualize the annual incidences … population pyramids from 1970 to 2070…

5 min read · May 18, 2024 8 min read · May 19, 2024

71 2 7

Bo Yuan, Ph.D.

Create a Heatmap in R ggplot2 to


Visualize African Population…
Heatmaps are powerful tools in data
visualization, and the famous ggplot2…

2 min read · May 8, 2024

72

See all from Bo Yuan, Ph.D.

Recommended from Medium


Manushi Mukhi in Accredian Gabe Araujo, M.Sc. in Level Up Coding

Kolmogorov–Arnold Networks How I Automated My Life: Practical


(KAN) Are About To Change The … Python Scripts for Everyday Tasks
Forget Everything You Know About Neural By automating repetitive tasks, you can free
Networks, KANs Are Here to Rewrite the… up valuable time and focus on activities that…

5 min read · May 10, 2024 · 14 min read · May 16, 2023

1.1K 17 1.1K 16

Lists

Predictive Modeling w/ Practical Guides to Machine


Python Learning
20 stories · 1252 saves 10 stories · 1510 saves

ChatGPT prompts Coding & Development


47 stories · 1637 saves 11 stories · 640 saves
Torsten Walbaum in Towards Data Science Axel Casas, PhD Candid… in Python in Plain Engli…

What 10 Years at Uber, Meta and 4 Must Read Python Books To


Startups Taught Me About Data… Boost Your Skills By 10000%
Advice for Data Scientists and Managers Start learning Python easily, fast, and while
having fun

9 min read · 6 days ago · 7 min read · May 9, 2024

1.5K 24 1.1K 6

XAI4HEAT Iwa Sanjaya in Microsoft Power BI

Multivariate Outlier Detection: A Data Storytelling 101: Using Color


Game Changer in Understanding… Strategically for Impactful…
In the world of industrial data analysis, outlier This article explores the crucial role of gray
detection stands as a crucial technique for… color in enhancing data visualization for…

20 min read · Jan 25, 2024 5 min read · May 25, 2024

81 1 68

See more recommendations

You might also like