This document uses the data about the COVID-19 provided by the Johns Hopkins CSSE Github. But any data could be used!
Auto Update your Data
Auto Update your Data
If you have Github installed on your system, you can use the following command to update an initialized copy of the ... university Github repertory (https://github.com/CSSEGISandData/COVID-19).
SetDirectory["path"];RunProcess[{"git","pull"},"StandardOutput"]
Out[]=
Already up to date.
Getting The Map (Without the use of Database)
Getting The Map (Without the use of Database)
The following commands allow you to prepare a basic map (cylindric projection) using GEOJSON data files that contain a polygon for each country. The one used here is available on the here: https://cdn.eintel.net/Downloads/coast.geojson . I forgot the original source, I think it was this one: https://datahub.io/core/geo-countries#resource-countries
countryPoly=Import["path","JSON"];countryPolyDs=(Association[Flatten[{"properties"/.#,"geometry"/.#}]]&/@Values[countryPoly[[2]]])//Dataset;
So the database look like that:
countryPolyDs//Take[#,3]&
Out[]=
And all the available countries are named has such:
countriesAvailable=countryPolyDs[;;,"ADMIN"]//Normal;Multicolumn[countriesAvailable,4]
Out[]=
Aruba | Denmark | Laos | Rwanda |
Afghanistan | Dominican Republic | Lebanon | Western Sahara |
Angola | Algeria | Liberia | Saudi Arabia |
Anguilla | Ecuador | Libya | Scarborough Reef |
Albania | Egypt | Saint Lucia | Sudan |
Aland | Eritrea | Liechtenstein | South Sudan |
Andorra | Dhekelia Sovereign Base Area | Sri Lanka | Senegal |
United Arab Emirates | Spain | Lesotho | Serranilla Bank |
Argentina | Estonia | Lithuania | Singapore |
Armenia | Ethiopia | Luxembourg | South Georgia and South Sandwich Islands |
American Samoa | Finland | Latvia | Saint Helena |
Antarctica | Fiji | Macao S.A.R | Solomon Islands |
Ashmore and Cartier Islands | Falkland Islands | Saint Martin | Sierra Leone |
French Southern and Antarctic Lands | France | Morocco | El Salvador |
Antigua and Barbuda | Faroe Islands | Monaco | San Marino |
Australia | Federated States of Micronesia | Moldova | Somaliland |
Austria | Gabon | Madagascar | Somalia |
Azerbaijan | United Kingdom | Maldives | Saint Pierre and Miquelon |
Burundi | Georgia | Mexico | Republic of Serbia |
Belgium | Guernsey | Marshall Islands | Sao Tome and Principe |
Benin | Ghana | Macedonia | Suriname |
Burkina Faso | Gibraltar | Mali | Slovakia |
Bangladesh | Guinea | Malta | Slovenia |
Bulgaria | Gambia | Myanmar | Sweden |
Bahrain | Guinea Bissau | Montenegro | Swaziland |
The Bahamas | Equatorial Guinea | Mongolia | Sint Maarten |
Bosnia and Herzegovina | Greece | Northern Mariana Islands | Seychelles |
Bajo Nuevo Bank (Petrel Is.) | Grenada | Mozambique | Syria |
Saint Barthelemy | Greenland | Mauritania | Turks and Caicos Islands |
Belarus | Guatemala | Montserrat | Chad |
Belize | Guam | Mauritius | Togo |
Bermuda | Guyana | Malawi | Thailand |
Bolivia | Hong Kong S.A.R. | Malaysia | Tajikistan |
Brazil | Heard Island and McDonald Islands | Namibia | Turkmenistan |
Barbados | Honduras | New Caledonia | East Timor |
Brunei | Croatia | Niger | Tonga |
Bhutan | Haiti | Norfolk Island | Trinidad and Tobago |
Botswana | Hungary | Nigeria | Tunisia |
Central African Republic | Indonesia | Nicaragua | Turkey |
Canada | Isle of Man | Niue | Tuvalu |
Switzerland | India | Netherlands | Taiwan |
Chile | Indian Ocean Territories | Norway | United Republic of Tanzania |
China | British Indian Ocean Territory | Nepal | Uganda |
Ivory Coast | Ireland | Nauru | Ukraine |
Clipperton Island | Iran | New Zealand | United States Minor Outlying Islands |
Cameroon | Iraq | Oman | Uruguay |
Cyprus No Mans Area | Iceland | Pakistan | United States of America |
Democratic Republic of the Congo | Israel | Panama | US Naval Base Guantanamo Bay |
Republic of Congo | Italy | Pitcairn Islands | Uzbekistan |
Cook Islands | Jamaica | Peru | Vatican |
Colombia | Jersey | Spratly Islands | Saint Vincent and the Grenadines |
Comoros | Jordan | Philippines | Venezuela |
Cape Verde | Japan | Palau | British Virgin Islands |
Costa Rica | Baykonur Cosmodrome | Papua New Guinea | United States Virgin Islands |
Coral Sea Islands | Siachen Glacier | Poland | Vietnam |
Cuba | Kazakhstan | Puerto Rico | Vanuatu |
Curaçao | Kenya | North Korea | Wallis and Futuna |
Cayman Islands | Kyrgyzstan | Portugal | Akrotiri Sovereign Base Area |
Northern Cyprus | Cambodia | Paraguay | Samoa |
Cyprus | Kiribati | Palestine | Yemen |
Czech Republic | Saint Kitts and Nevis | French Polynesia | South Africa |
Germany | South Korea | Qatar | Zambia |
Djibouti | Kosovo | Romania | Zimbabwe |
Dominica | Kuwait | Russia | |
The following function gets the polygon data contained in the JSON and prepare Mathematica Polygon objects.
In[]:=
getPoly[target_String]:=If[countryPolyDs[SelectFirst[#ADMINtarget&],#type&]"MultiPolygon",Polygon/@(countryPolyDs[SelectFirst[#ADMINtarget&],#coordinates&]//Normal),Polygon[countryPolyDs[SelectFirst[#ADMINtarget&],#coordinates&]//Normal]];
Now we can create a basemap:
basemap={EdgeForm[{Thin,Black}],FaceForm[White]}~Join~Join[(getPoly/@countriesAvailable)];basemap//Graphics[#,Background->LightBlue,ImageSizeLarge]&//Rasterize
Out[]=
Using ColorData we can add a bit of color on the basemap. I think you are guessing how we will put our data on the map!
{EdgeForm[{Thin,Black}]}~Join~Join[Riffle[getPoly/@countriesAvailable,FaceForm[{#}]&/@ColorData[35,"ColorList"]]]//Graphics[#,Background->LightBlue,ImageSizeLarge]&//Rasterize
Out[]=
Getting the data from the Github repertory
Getting the data from the Github repertory
First we load the data from each file, then we will interpret them. We use the interpreter for the number, and we apply the DateObject function on the right columns. The DateObject function will return few errors because of the date formatting that was used in the first versions.
Let’s take the data from yesterday, we suppose they are complete. We could use the data from today, but the Github might not have been updated.
Some countries won’t be recognized because they are named differently. Here I correct some, but I’ll let few to show the differences.
Preparing the 2D Map
Preparing the 2D Map
The 2D map is the important one since it is more useful in many situations to work with two-dimensional representations. Still we will make a 3D globe in the next section!
Countries in the data:
Some countries were not recognized, I corrected some of them already in the previous section:
Now we are ready to colour our map!
Globe representation
Globe representation
This step is easier than I was thinking. Using SphericalPlot, we can apply a Texture on the sphere with the right mapping. The Automatic TextureCoordinateFunction from SphericalPlot does the hard work for us! Note the rotation I did on the picture.