knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(c19euxplorer)

c19euxplorer features a Shiny app to explore the data of COVID-19 related variables in several countries in Europe. The variables covered are daily and cumulative cases and deaths, weekly testing and positivity rate, weekly dominant source of transmission, and daily community mobility during the pandemic. This package also contains several other functions to simplify the codes used in the app.

The app's sources of data are the European Centre of Disease Prevention and Control and the Google Community Mobility Report. The cumulative figures and GCMR are downloaded with the tidycovid19 R package.

Package Usage

Main Usage

The main purpose if this app is a container of a Shiny app package to explore COVID-19 related variables in several countries in Europe. To use this feature, you can use the launch_app function.

#> launch the app
#> make sure to have all of the packages in suggest installed 
launch_app()

The launched app would appear as follow:

knitr::include_graphics("https://datain360.com/posts/2020-10-14-shinyselfreview/shiny_gif/my_shiny.gif")


This app comprises of seven tabs as follow:

  1. Home. This tab is a landing page of the app. It gives a very brief overview of the app and the urge to explore the app by clicking each tab in the navbar.
  2. Cases and Deaths. You can visualize the cases and deaths of COVID-19 in 51 countries in Europe in daily and cumulative-wise. You can also compare several countries with a certain range of date.
  3. Testing. You can explore the COVID-19 weekly testing and positivity rates in 30 countries in Europe (EU/EEA member countries and UK). You can also compare certain countries within certain week range. If you wish to use the data only without launch the app, this package contains that data for your own purpose.
library(tibble)
tibble(c19euxplorer::testing_weekly_eu)


  1. Tracing. The content of this tab is the visualization of weekly dominant source of COVID-19 transmission that aggregated from subnational level of 32 countries in Europe. In this tab, you can only visualize one certain country interactively. I also provided a bubble map to choose a country based on its rate of cases per 10,000 people. If you wish to explore the raw data, apart from the app, you can use this code below, since this package contains that data.
tibble(c19euxplorer::transmission_subnational_level)


  1. Community Mobility. The objective of this tab is to explore the mobility of people during the pandemic in six types of locations daily. You are able to choose a country to be displayed. You can also choose the time range. I also added an interactive table of country response measure, which shows the start date and the end date of a measure. Since community mobility is developed to observe the effect of measure to the community activity, this table is useful as a benchmark of choosing the date to track that effect.
  2. Data. This tab displays the raw data that are used to visualize the variables in the previous tabs. The users are allowed to choose one or more countries, even select all of the countries available. They are also allowed to choose the time range.
  3. More. This tab contains two sub-tabs: About and References. The About sub-tab specifies the purpose of the app and other relevant information, such as the data source used in the app and the R packages to make the app. There is also a brief information of my self. The References sub-tab conveys the reference of data sources, readings, packages, and images used in the app.

Additional Usage

Country Centroids Data

Besides those two data sets, I also embedded a country centroids data set. Apart from COVID-19 matter, this data set is useful if you wish to make a bubble map with a point represents a whole country, such as the following map:

tibble(c19euxplorer::country_centroids)
library(dplyr)
library(ggplot2)
library(maps)
library(viridis)
library(viridisLite)

#> data to be mapped
plot <- testing_weekly_eu

#> country centroid
centro <- country_centroids %>%
  rename(country = name_long)

#> join the those two data sets
pop_map <- left_join(plot, centro, by = "country") %>%
  filter(year_week == "2020-W20")

#> load world map
world_map <- map_data("world")
#>the map
ggplot() +
      geom_polygon(data = world_map, 
                   aes(x = long,
                       y = lat,
                       group = group),
                   fill = "#73C6B6",
                   colour = "white",
                   alpha = 0.7
      ) +
      geom_point(data = pop_map,
                 aes(x = Longitude,
                     y = Latitude,
                     colour = population,
                     size = population,
                     alpha = population)) +
      scale_size_continuous(range = c(1, 6)) +
      scale_color_viridis(option = "inferno", trans = "log") +
      scale_alpha_continuous(trans = "log") +
      guides(colour = guide_legend()) + 
      xlab("") +
      ylab("") +
      theme(panel.grid = element_blank(),
            axis.title = element_blank(),
            axis.text = element_blank(),
            axis.ticks = element_blank(),
            plot.background = element_rect(fill = "white"),
            panel.background = element_rect(fill = "white")) +
  labs(title = "Population Bubble Map")



daily_indicator()

This function aims to simplify the code in c19euxplorer shiny app by selecting country, date, and indicators in daily data to be visualized in Cases and Deaths tab. This function would be used in the app, although you can also use this function outside the app. However, make sure to have these variables (with the exact same name) in your data frame in order to make the function works.

plot_daily <- plot %>%
  rename(daily_cases = new_cases,
         date = year_week) 

plot_daily_new <- daily_indicator(plot_daily, "Cases")
tibble(plot_daily_new)


getplot()

Here, I would give you an example of the usage of getplot() function. We could use plot_cumulative to make a plot. However, since there are a lot of countries, we would like to choose only several countries.

library(lubridate)
for_plot <- plot_daily_new %>%
  mutate(week_only = as.numeric(sub(".*W", "", date))) %>%
  filter(country %in% c("Austria", "Spain", "United Kingdom")) %>% 
  mutate(date = as.Date(paste(2020, week_only, 1, sep="-"), "%Y-%U-%u"))

getplot(for_plot)


getref()

Currently, I have not found a package that facilitate the creation of reference in Shiny. So, I made this function to make the reference writing come in handy.

Using the HTML tag provided by Shiny, you have to type this code to create a reference like this:

tags$li(class = "li-custom", "Winston Chang. (2018).",
        tags$a(href = "https://CRAN.R-project.org/package=shinythemes",
              "shinythemes: Themes for Shiny",
              class = "externallink"))

Winston Chang. (2018). shinythemes: Themes for Shiny


With getref(), you just have to type this:

getref("Winston Chang",
       "2018",
       "https://CRAN.R-project.org/package=shinythemes",
       "shinythemes: Themes for Shiny")


getlink()

Just like getref(), getlink() also aims to simplify the typing of link in Shiny app's UI using the HTML tag. Initially, Shiny has a markdown function to also make this task easier. However, markdown adds the new hyperlink text into a new line. Sometimes, we want to use some hyperlink texts in one sentences.

Using HTML tag, you have to type this code to create this hyperlink text:

Master of Business Analytics

tags$a(href = "https://www.monash.edu/study/courses/find-a-course/2021/business-analytics-b6022?gclid=EAIaIQobChMI5bKC_Y-g7AIVzn8rCh3aQABbEAAYASAAEgK09PD_BwE&international=true#overview-1",
       "Master of Business Analytics",
       class = "externallink")


With getlink(), you can just type this:

getlink("https://www.monash.edu/study/courses/find-a-course/2021/business-analytics-b6022?gclid=EAIaIQobChMI5bKC_Y-g7AIVzn8rCh3aQABbEAAYASAAEgK09PD_BwE&international=true#overview-1",
        "Master of Business Analytics")


etc5523-2020/r-package-assessment-Dewi-Amaliah documentation built on Jan. 1, 2021, 1:10 a.m.