The world’s leading publication for data science, AI, and ML professionals.

Coronavirus data visualizations using Plotly

An analysis of the Novel Corona Virus 2019 Dataset with code

!

Introduction

Today, I found a new dataset called the ‘Novel Corona Virus 2019 Dataset,’ and because there was so much interest in my previous article, 9 fascinating Novel Coronavirus statistics and data visualizations, I thought I would create some Data visualizations using Plotly!

Plotly is a library in Python used to create interactive and dynamic data visualizations. I’ll provide a link to my Kaggle Notebook at the bottom of this article in case you want to interact with any of these visualizations.

Note: All images and GIFs were created by myself using Plotly and Giphy.

_If this is the kind of stuff that you like, be one of the FIRST to subscribe to my new YouTube channel here! While there aren’t any videos yet, I’ll be sharing lots of amazing content like this but in video form. Thanks for your support 🙂_

Table of Content

  1. Choropleth Maps
  2. Pie Charts
  3. Bar Graphs
  4. Line Graphs
  5. Treemaps

Choropleth Maps

Spread of the Coronavirus Globally Over Time

  • This is an animated choropleth which shows where the coronavirus has spread in the month of February 2020. If you want to see a clearer version of the full thing, the link is at the bottom of this article!
fig = px.choropleth(df_countrydate, 
                    locations="Country", 
                    locationmode = "country names",
                    color="Confirmed", 
                    hover_name="Country", 
                    animation_frame="Date"
                   )

fig.update_layout(
    title_text = 'Spread of Coronavirus',
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
    ))

fig.show()

Heatmap of Confirmed Cases Globally

Created using plot.ly
Created using plot.ly
  • It’s clear that the number of cases in China is incomparable to any other country that has any confirmed cases. Therefore, I removed China from the analysis in the next picture.
fig = go.Figure(data=go.Choropleth(
    locations = df_countries['Country'],
    locationmode = 'country names',
    z = df_countries['Confirmed'],
    colorscale = 'Reds',
    marker_line_color = 'black',
    marker_line_width = 0.5,
))

fig.update_layout(
    title_text = 'Confirmed Cases as of February 28, 2020',
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
        projection_type = 'equirectangular'
    )
)

Heatmap of Confirmed Cases Globally excl. China

Created using plot.ly
Created using plot.ly
  • Here, you can see that three countries that evidently have the highest number of cases, besides China, is South Korea, Iran, and Italy.
df_countries_no_china = df_countries[df_countries['Country'] != 'Mainland China']
fig = go.Figure(data=go.Choropleth(
    locations = df_countries_no_china['Country'],
    locationmode = 'country names',
    z = df_countries_no_china['Confirmed'],
    colorscale = 'Reds',
    marker_line_color = 'black',
    marker_line_width = 0.5
))

fig.update_layout(
    title_text = 'Confirmed Cases as of February 28, 2020 excl. China',
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
        projection_type = 'equirectangular'
    )
)

Pie Charts

Proportion of Confirmed Cases by Country

  • It’s clear that the majority of cases remain in China, but in the next picture you can see the proportion of cases outside of China
fig = px.pie(df_countries, values = 'Confirmed',names='Country', height=600)
fig.update_traces(textposition='inside', textinfo='percent+label')

fig.update_layout(
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
    ))

fig.show()

Proportion of Confirmed Cases by Country excl. China

  • ‘Other’ refers to cases from the Diamond Princess Cruise Ship
fig = px.pie(df_countries_no_china, values = 'Confirmed',names='Country', height=600)
fig.update_traces(textposition='inside', textinfo='percent+label')

fig.update_layout(
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
    ))

fig.show()

Bar Graphs

Total Number of Confirmed Cases Over Time

  • There was a major spike on February 13th, due to a new method of reclassifying confirmed cases
  • It started to plateau, but because of the release of the members on the Diamond Cruise Ship, you could see an increasing number of countries with cases towards the end of February. This may suggest that the spread of the virus is far from plateauing.

Total Number of Deaths Over Time

Total Number of Recovered Cases Over Time

  • The number of deaths and recovered cases are lagging indicators, so we should see some numbers racking up in other countries as the weeks go by.
bar_data = df.groupby(['Country', 'Date'])['Confirmed', 'Deaths', 'Recovered'].sum().reset_index().sort_values('Date', ascending=True)

fig = px.bar(bar_data, x="Date", y="Confirmed", color='Country', text = 'Confirmed', orientation='v', height=600,
             title='Cases')
fig.show()

fig = px.bar(bar_data, x="Date", y="Deaths", color='Country', text = 'Deaths', orientation='v', height=600,
             title='Deaths')
fig.show()

fig = px.bar(bar_data, x="Date", y="Recovered", color='Country', text = 'Recovered', orientation='v', height=600,
             title='Recovered')
fig.show()

Line Graph

  • This is a consolidated representation of the bar graphs shown above. Ideally, we would like to see the red line and blue line converge and pass each other.
line_data = df.groupby('Date').sum().reset_index()

line_data = line_data.melt(id_vars='Date', 
                 value_vars=['Confirmed', 
                             'Recovered', 
                             'Deaths'], 
                 var_name='Ratio', 
                 value_name='Value')

fig = px.line(line_data, x="Date", y="Value", color='Ratio', 
              title='Confirmed cases, Recovered cases, and Death Over Time')
fig.show()

Treemaps

Treemaps are a similar representation to pie charts in that it represents proportions.

Confirmed Cases by Country

fig = px.treemap(df_countries, path=['Country'], values='Confirmed', height=600, width=1000)

fig.update_layout(
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
    ))

fig.show()

Confirmed Cases by Country excl. China

fig = px.treemap(df_countries_no_china, path=['Country'], values='Confirmed', height=600, width=1000)

fig.update_layout(
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
    ))

fig.show()

Thanks for Reading!

If you like my work and want to support me…

  1. The BEST way to support me is by following me on Medium here.
  2. Be one of the FIRST to follow me on Twitter here. I’ll be posting lots of updates and interesting stuff here!
  3. Also, be one of the FIRST to subscribe to my new YouTube channel here!
  4. Follow me on LinkedIn here.
  5. Sign up on my email list here.
  6. Check out my website, terenceshin.com.

More Related Articles

9 fascinating Novel Coronavirus statistics and data visualizations

An Extensive Step by Step Guide to Exploratory Data Analysis

Resources

Choropleth Maps

Figure Reference

Plotly Express


Related Articles