Zoom Plotting
Loading a Julia object
We will load the object we saved in the last chapter into this session so that we can plot the data.
To successfully load the BSON file and recreate our DataFrame, we need to load in this session all the packages that were involved in the creation of the DataFrames so that the necessary types are available to Julia.
In addition, we will load the StatsPlots package which is a version of the Plots package with some additional statistical functionality:
using BSON
using DataFrames
using Dates # from the standard Julia library
using TimeSeries
using StatsPlots
Plots (and thus StatsPlots) is built on top of various visualization backends (e.g.ย Plotly or GR ). This allows to use the same code to run any of these backends. The GR framework is used by default.
BSON.@load "deaths_canada.bson" deaths_canada
Time series
Our data is a time series and needs to be transformed into a TimeArray thanks to the TimeArray
function from the TimeSeries package before it can be plotted:
deaths_canada = TimeArray(deaths_canada, timestamp = :date)
861ร1 TimeArray{Int64, 1, Date, Vector{Int64}} 2020-01-22 to 2022-05-31
โ โ number_deaths_sum โ
โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโค
โ 2020-01-22 โ 0 โ
โ 2020-01-23 โ 0 โ
โ 2020-01-24 โ 0 โ
โ 2020-01-25 โ 0 โ
โ 2020-01-26 โ 0 โ
โ 2020-01-27 โ 0 โ
โ 2020-01-28 โ 0 โ
โ 2020-01-29 โ 0 โ
โ 2020-01-30 โ 0 โ
โ 2020-01-31 โ 0 โ
โ 2020-02-01 โ 0 โ
โ โฎ โ โฎ โ
โ 2022-05-22 โ 40740 โ
โ 2022-05-23 โ 40740 โ
โ 2022-05-24 โ 40745 โ
โ 2022-05-25 โ 40838 โ
โ 2022-05-26 โ 40952 โ
โ 2022-05-27 โ 41016 โ
โ 2022-05-28 โ 41039 โ
โ 2022-05-29 โ 41042 โ
โ 2022-05-30 โ 41043 โ
โ 2022-05-31 โ 41070 โ
We are now ready to create a plot.
Creating a plot
Creating a plot is very simple:
plot(deaths_canada)
Customization
Of course, some amount of tweaking is needed to make a plot nicer. Here, let’s simply add a title and remove the unnecessary legend:
plot(deaths_canada, title="Cumulative number of Covid-19 deaths in Canada", legend=false)