Top R resources on Coronavirus
As a data lover myself, I discovered a multitude of great resources about the Coronavirus. However, these resources were spread all over the internet and were often hidden by the mass of information of another type (e.g., alarming headlines, names of infected celebrities, companies showing off how they helped health care agencies, etc.). To tackle this issue, I collected and then shared in a previous article the best R resources on the Coronavirus I came across.
Note that only resources on R are shared in this article as R is my favorite statistical program and the one I am most familiar with. The fact that I use this program almost daily makes it easier for me to realize the complexity and time put behind a resource, and appreciate its quality and its potential.
I am sure that there are other very interesting resources online (see for example the probably most popular dashboard by the Johns Hopkins Coronavirus Resource Center). Nonetheless, a lot of people are in a better position than I am to judge the quality of resources made with programming languages for which I am not competent.
This article made me discover so many great resources about the Coronavirus and I keep receiving data visualizations and data analyses from scientists all over the world so that I include them in the collection. Thanks for that, it continuously improves the quality and completeness of the collection.
In addition to receiving R resources, a question often asked by readers was “How can I create a dashboard myself?” or “How can I build a dashboard specific to my country?”. I therefore thought it would serve some people if I created a dashboard specific to my country (Belgium) and detailed the steps on how to build it.
Questions on how to develop such dashboards came mostly from R beginners as advanced R users most probably know how to do one, or at least can easily use the resources I collected here as sources of inspiration for their own work. Furthermore, in response to the craze about the Coronavirus, interested users were quite in a hurry and wanted to have their own dashboard running as quickly as possible.
These questions led me to the idea of creating a simple (yet powerful and visually appealing) dashboard, as opposed to a Shiny app. Shiny apps have the advantage that they are interactive in the sense that users can edit the outputs and the visualizations by simply changing some inputs in a user-friendly way, while dashboards are static and cannot be modified by the final user. On the other hand, the advantage of a dashboard over a Shiny app is that it is much easier to code, especially if you are already proficient in R Markdown.
How to create your own Coronavirus dashboard
If you want to build your own dashboard specific to a country, follow these steps:
- Open the dashboard here
- See the entire code via the button “Source code” located in the top right corner of the dashboard, or see the code on GitHub. Copy that code.
- Open a new R Markdown file (
.Rmd
), type any title and author (they will be replaced in the next step anyway), select HTML as the output format and click on OK:
- Remove all the template code already present and paste the code you copied in step 1.
- Make sure that the required packages are installed:
install.packages(c("devtools", "flexdashboard", "leaflet", "leafpop"))
devtools::install_github("RamiKrispin/coronavirus", force = TRUE)
If R asks you which package you would like to update, there should be no need to update them: type 3 for “None”.
- In the code, replace
Belgium
with your country. Here is the list of all available countries in the dataset:
Canada, United Kingdom, China, Netherlands, Australia, New Zealand, Denmark, France, Afghanistan, Albania, Algeria, Andorra, Angola, Antarctica, Antigua and Barbuda, Argentina, Armenia, Austria, Azerbaijan, Bahamas, Bahrain, Bangladesh, Barbados, Belarus, Belgium, Belize, Benin, Bhutan, Bolivia, Bosnia and Herzegovina, Botswana, Brazil, Brunei, Bulgaria, Burkina Faso, Burma, Burundi, Cabo Verde, Cambodia, Cameroon, Central African Republic, Chad, Chile, Colombia, Comoros, Congo (Brazzaville), Congo (Kinshasa), Costa Rica, Cote d’Ivoire, Croatia, Cuba, Cyprus, Czechia, Diamond Princess, Djibouti, Dominica, Dominican Republic, Ecuador, Egypt, El Salvador, Equatorial Guinea, Eritrea, Estonia, Eswatini, Ethiopia, Fiji, Finland, Gabon, Gambia, Georgia, Germany, Ghana, Greece, Grenada, Guatemala, Guinea, Guinea-Bissau, Guyana, Haiti, Holy See, Honduras, Hungary, Iceland, India, Indonesia, Iran, Iraq, Ireland, Israel, Italy, Jamaica, Japan, Jordan, Kazakhstan, Kenya, Kiribati, Korea, North, Korea, South, Kosovo, Kuwait, Kyrgyzstan, Laos, Latvia, Lebanon, Lesotho, Liberia, Libya, Liechtenstein, Lithuania, Luxembourg, Madagascar, Malawi, Malaysia, Maldives, Mali, Malta, Marshall Islands, Mauritania, Mauritius, Mexico, Micronesia, Moldova, Monaco, Mongolia, Montenegro, Morocco, Mozambique, MS Zaandam, Namibia, Nepal, Nicaragua, Niger, Nigeria, North Macedonia, Norway, Oman, Pakistan, Palau, Panama, Papua New Guinea, Paraguay, Peru, Philippines, Poland, Portugal, Qatar, Romania, Russia, Rwanda, Saint Kitts and Nevis, Saint Lucia, Saint Vincent and the Grenadines, Samoa, San Marino, Sao Tome and Principe, Saudi Arabia, Senegal, Serbia, Seychelles, Sierra Leone, Singapore, Slovakia, Slovenia, Solomon Islands, Somalia, South Africa, South Sudan, Spain, Sri Lanka, Sudan, Summer Olympics 2020, Suriname, Sweden, Switzerland, Syria, _Taiwan*_, Tajikistan, Tanzania, Thailand, Timor-Leste, Togo, Tonga, Trinidad and Tobago, Tunisia, Turkey, Uganda, Ukraine, United Arab Emirates, Uruguay, US, Uzbekistan, Vanuatu, Venezuela, Vietnam, West Bank and Gaza, Winter Olympics 2022, Yemen, Zambia and Zimbabwe
Note that if your country is spelled in two words or more, you will need to surround it by a backtick (but only at one specific line in the code, see an example with United Kingdom):
#----------------------------------------
# Plotting the data
daily_confirmed %>%
plotly::plot_ly() %>%
plotly::add_trace(
x = ~date,
y = ~`United Kingdom`,
type = "scatter",
mode = "lines+markers",
name = "United Kingdom"
) %>%
Do not add backticks in the rest of the code as everywhere else the country’s name is surrounded by double quotes ""
.
Do not forget to also change the title and the author at the top of the document, and edit the about section at the bottom of the document. Last but not least, as you can see on the plot in the summary section, the arrows point to different (sad) “milestones” in Belgium (i.e., first case, first death and new containment measures).
You will need to adapt these milestones for your country (or remove them if you do not want to have any milestone displayed on the plot). Change this in the code following the plotly::add_annotations()
functions.
- Knit the document (see this article if you are unfamiliar with R Markdown). Your dashboard should appear in HTML format.
Following these 7 steps, you should already have a simple dashboard specific to your country. I have intentionally kept it simple so that everyone could copy it and have their own dashboard in a limited amount of time.
If you are familiar with the {flexdashboard}
, {plotly}
and {leaflet}
packages for the dashboard interface and the visualizations, and the {dplyr}
and {tidyr}
packages for the data manipulation, feel free to edit the code according to your needs and improve your dashboard.