Bioconductor Website Redesign

Survey response numbers

Published

June 24, 2023

Survey Link: https://t.maze.co/169169456.
Survey Open: June 13 2023 - June 23 2023

Map of response numbers by country

Show code
# Load packages
library(tidyverse)
library(countrycode)
library(maps)
library(plotly)
library(reactable)

# Import survey data
d <- read_csv("maze_169169456_block_9ddce458-867d-4f3b-85a4-93d015455926_sessions.csv")

# Standardise country names
d_countries <- d |> 
  mutate(country = countrycode(value, origin = "country.name", destination = "country.name", origin_regex = TRUE)) 

# Fix country text not matched
d_clean <- d_countries |> 
  mutate(country = 
    case_when(toupper(value) == "NL" ~ "Netherlands",
              value == "England" ~ "United Kingdom",
              value == "the U.K." ~ "United Kingdom",
              value == "CH\n" ~ "Switzerland",
              value == "中国" ~ "China",
              value == "PRC" ~ "China",
              value == "China, Australia" ~ "China",
              value == "México" ~ "Mexico",
              value == "Brasil" ~ "Brazil",
              TRUE ~ country))

# Add continents
d_clean <- d_clean |> 
    mutate(continent = countrycode(country, origin = "country.name", destination = "continent"))

# Get counts per country
country_counts <- 
  d_clean |> 
  group_by(country) |>
  mutate(n = n()) |>
  select(continent, country, n) |>
  distinct() |>
  mutate(country = replace_na(country, "NA"), continent = replace_na(continent, "NA")) # some countries can't match (asad, 1) so show as NA

# Plot map
world_map <- map_data("world")
world_map <- subset(world_map, region != "Antarctica")

# Standarise the region to the country names 
world_map <- world_map |>
mutate(country = countrycode(region, origin = "country.name", destination = "country.name", origin_regex = TRUE))

# Merge the datasets
world_map <- world_map %>%
  left_join(country_counts) |>
  mutate(n = replace_na(n, 0))

# Plot
gg <- ggplot() +
  geom_polygon(data = world_map, 
               aes(x = long, y = lat, group = group, fill = n, text = paste(country, n, sep = "\n")), 
               colour = "grey", 
               linewidth = 0.25) +
  scale_fill_gradient(low = "white", high = "red") + 
  theme_minimal() +
  theme(legend.position = "bottom") +
  labs(fill = "n") 


ggplotly(gg, tooltip = "text") |> 
  layout(legend = list(orientation = "h", x = 0.25, y = -0.02)) |>
  partial_bundle() # reduce html file size

Table of response numbers by continent

Show code
country_counts |> 
  group_by(continent) |>
  summarise(n = sum(n)) |>
  reactable(striped = TRUE, 
            defaultSorted = "n", 
            defaultSortOrder = "desc",
            columns = list(
              continent = colDef(footer = "Total"),
              n = colDef(footer = function(values) sum(values))),
            defaultColDef = colDef(footerStyle = list(fontWeight = "bold")))

Table of response numbers by country

Show code
country_counts |>
  reactable(defaultSorted = "n", 
            defaultSortOrder = "desc", 
            searchable = TRUE, 
            striped = TRUE, 
            defaultPageSize = 300,
            columns = list(
              continent = colDef(footer = "Total"),
              n = colDef(footer = function(values) sum(values))),
            defaultColDef = colDef(footerStyle = list(fontWeight = "bold")))