Skip to content

Instantly share code, notes, and snippets.

@sguzman
Created March 20, 2021 20:23
Show Gist options
  • Save sguzman/6eee90055873d37a6e2d70ea5d921075 to your computer and use it in GitHub Desktop.
Save sguzman/6eee90055873d37a6e2d70ea5d921075 to your computer and use it in GitHub Desktop.
Study countries by region
diff[ts_] := Transpose[{
ts["Dates"][[;; -2]],
Differences@ts["Values"]
}];
merge[list_] := GatherBy[
Table[
Splice@
diff[l]
, {l, list}]
, First];
mmerge[list_] := Table[
{First@First@g, Total@Map[Last, g]},
{g, merge[list]}];
With[{list = {"Americas", "Europe", "Africa", "MiddleEast", "Asia",
"Oceania"}},
DateListPlot[
Table[
mmerge@
DeleteMissing@
Table[
CountryData[b, {"Population", All}]
, {b, a}]
, {a, Map[CountryData, list]}]
, Joined -> False, PlotRange -> Full, AspectRatio -> 1/3,
ImageSize -> Full, PlotLegends -> list
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment