Flight of Corona — a visualization journey around the earth in R

Harish Nagpal
Analytics Vidhya
Published in
6 min readMar 24, 2020

--

Corona journey around the world after it started from China

On December 31st, 2019, Chinese Authorities confirmed the presence of a new kind of pneumonia. The origin was traced to a meat market in Wuhan, the epicenter of Corona.

Later Chinese authorities named it nCov or novel corona virus. Since its discovery in the month of January, its has spread like a wild fire all over the world and has infected more than 3,60,000 people around the word and killing more than 16000 people as on 24/03/2020.

This has been so far the deadliest attack on human by an invisible virus and so far medical scientists are working 24 hrs a day to find the vaccination for its cure.

In this article, I have tried to visualize the journey of Corona and how it has become a global pandemic through visualization.

I am using R and three.js package to visualize Corona journey and the spread around the globe.

As per cran.r wesite, threejs package supports interactive 3D graphics including point clouds and globes using three.js and htmlwidgets. Find full details here. I have used the code from here and put the Corona data set in same code. So credit of this article goes to cran.r-project.org.

The data has been taken from GitHub as on 21/03/2020. All the longitudes and latitudes have also been taken from the same data. This data is updated every day and is considered most authentic data. Find the link of the data here. The data is in the form of summarized data and time series data. In this article I am using summarized data. Here is the first look of the data

Initial data @ GitHub site

This data contains confirmed, deaths and recovered cases every day. You can find the country/region and the province/state where it spread.

While using this data, I had to clean it first. For some countries, data is appearing State wise like US, China, UK etc. So I had to summarize the data manually country wises and then put it in a separate file. For some countries I had to manually add the Latitude and Longitude. For some regions, I found that the Latitudes and Longitudes were pointing to sea (might be the Cruise Ship locations).

So here is the look of the cleaned data.

Since origin of the Corona is from Wuhan, we need to convert the data in such a way that we should have China’s latitude and longitude as origin and other countries as latitude and longitude destinations.

So I further worked on my data and here is the final data which can be shown to show the data as flights. You can see same longitude and latitude in C and D columns.

Final data set to show flight of Corona across globe

Visualization 1

Let us load the data set and read above file and see the data.

library(threejs)CoronaFlight <- read.csv(“D:/Harish/R practice projects/Corona/22March2020/21032020Data_Corona_Flight.csv”)CoronaFlight> CoronaFlight
dest_lat dest_long origin_lat origin_long
1 33.9391 67.7100 30.9756 112.2707
2 41.1533 20.1683 30.9756 112.2707
3 28.0339 1.6596 30.9756 112.2707
4 42.5063 1.5218 30.9756 112.2707
5 -11.2027 17.8739 30.9756 112.2707
6 17.0608 -61.7964 30.9756 112.2707
7 -38.4161 -63.6167 30.9756 112.2707
8 40.0691 45.0382 30.9756 112.2707
9 -33.8688 151.2093 30.9756 112.2707
10 47.5162 14.5501 30.9756 112.2707

Load the earth image. I used the image from NASA. You can also use earth image which comes with threejs package.

earth <- “http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73909/world.topo.bathy.200412.3x5400x2700.jpg"

So after this the code is very simple. Just put the data set in the code and see the magic. The arcs argument will automatically take the destinations and will show them like flights.

FlightOfCorona <- globejs(img=earth, lat=CoronaFlight[,3], long=CoronaFlight[,4], arcs=CoronaFlight,
arcsHeight=0.5, arcsLwd=1, arcsColor=”#ffff00", arcsOpacity=0.50,
atmosphere=TRUE)
FlightOfCorona

Once I got the output, I saved that as an html page, recorded that page and made an mp4 file and then made a gif out of it with the help of an online tool. And here is the final output. You can clearly see that how Corona spread from China to all countries. With the same code you can plot the data of air flights with different origins and destinations.

Visualization 2

Now with the same data as I showed you cleaned data in earlier section, I will show you the visualization of confirmed, death and recovered cases. Again package is same.


#load the package
library(threejs)
#set working directory
setwd(“D:/Harish/R practice projects/Corona/22March2020”)
#read the file
final = read.csv(“21032020Data_2.csv”)

Look at the column names

#look at the column names
colnames(final)
> colnames(final)
[1] “Country” “Confirmed” “Death” “Recovered” “Latitude” “Longitude”

The number of countries are 178.

nrow(final)> nrow(final)[1] 178

See the data.

head(final, n = 10)> head(final, n = 10)
Country Confirmed Death Recovered Latitude Longitude
1 Afghanistan 24 0 1 33.9391 67.7100
2 Albania 76 2 2 41.1533 20.1683
3 Algeria 139 15 32 28.0339 1.6596
4 Andorra 88 0 1 42.5063 1.5218
5 Angola 2 0 0 -11.2027 17.8739
6 Antigua and Barbuda 1 0 0 17.0608 -61.7964
7 Argentina 158 4 3 -38.4161 -63.6167
8 Armenia 160 0 1 40.0691 45.0382
9 Australia 1071 7 26 -33.8688 151.2093
10 Austria 2814 8 9 47.5162 14.5501

Now load the image of earth from here.

#find the earth image
earth <- “http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73909/world.topo.bathy.200412.3x5400x2700.jpg"

Let us visualize the confirmed cases with below code. Here in value you need to take the confirmed cases. Put latitude and longitude in lat and long arguments respectively. You can play with the code by putting different values like color, point size or with different images of earth.

confirmed <- globejs( img=earth, lat = final$Latitude, long = final$Longitude,
value = final$Confirmed,col = ‘#FFFF00’,
pointsize = 1.0,
atmosphere = TRUE)
confirmed

And here is the final out put. I used the same process as mentioned above in flight example. Bar denotes the number of confirmed cases. See the length of bar over China and European countries and Iran.

Corona confirmed cases

Let’s get the death cases with same data. Red bar denotes the number of death cases.

Death <- globejs( img=earth, lat = final$Latitude, long = final$Longitude,
value = final$Death, col = ‘#FF00001’,
pointsize = 2.0,
atmosphere = FALSE)
Death
Corona death cases

Let’s plot the recovered cases with same data. White bar denotes the number of death cases.

Recovered <- globejs( img=earth, lat = final$Latitude, long = final$Longitude,
value = final$Recovered, col = ‘#FFFFFF’,
pointsize = 2.0,
atmosphere = FALSE)
Recovered
Corona recovered cases

With this I am finishing my article. Thank for reading full article. Will meet soon with a new article.

Feel free to give your comments or mail me at harnagpal@gmail.com. Connect with me at Linkedin.

Have a look at my other articles on Medium.com

Election visualization with R

Create-beautiful-visualization-of-data-in-trelliscopejs-package-in-r-

See my data science maths art here.

References

Earth image

R threejs Pacakage

Data Source

cran-r

--

--

Harish Nagpal
Analytics Vidhya

An IT professional, passionate about art in all forms — data, nature, paintings and visual art. Linkedln — https://www.linkedin.com/in/harish-nagpal-8696529/