Skip to content

Instantly share code, notes, and snippets.

@RamiKrispin
Created July 3, 2021 14:01
Show Gist options
  • Select an option

  • Save RamiKrispin/fd70c25972a477a863c09492818ea068 to your computer and use it in GitHub Desktop.

Select an option

Save RamiKrispin/fd70c25972a477a863c09492818ea068 to your computer and use it in GitHub Desktop.
Distribution of San Francisco Vaccinated Population by Age Group
data("covid19sf_vaccine_demo")
d1 <- covid19sf_vaccine_demo
head(d1)
`%>%` <- magrittr::`%>%`
d1a <- covid19sf_vaccine_demo %>%
dplyr::filter(administering_provider_type == "All Providers",
demographic_group == "Age Bracket",
age_group == "All") %>%
dplyr::mutate(only_1st = total_1st_doses - total_2nd_doses,
not_vaccinated = subgroup_population - total_series_completed - only_1st,
first_per = 100 * only_1st / subgroup_population,
second_per = 100 * total_2nd_doses / subgroup_population,
single_per = 100 * total_single_doses / subgroup_population,
not_vaccinated_per = 100 * not_vaccinated / subgroup_population,
complete_per = 100 - not_vaccinated_per - first_per) %>%
dplyr::arrange(demographic_subgroup_sort_order) %>%
dplyr::mutate(age = factor(demographic_subgroup, levels = demographic_subgroup)) %>%
dplyr::select(age, first_per, second_per, single_per, not_vaccinated_per, complete_per)
d1a
library(plotly)
# parameters
font_size <- 22
opacity <- 0.95
background <- "rgb(225, 236, 242)"
complete_color <- paste("rgba(47, 106, 158,", opacity ,")", sep = "")
first_color <- paste("rgba(100, 184, 206,", opacity ,")", sep = "")
not_vaccinated_color <- paste("rgba(162, 32, 61,", opacity ,")", sep = "")
plot_ly(data = d1a,
x = ~ complete_per,
y = ~ age,
type = 'bar', orientation = 'h',
marker = list(color = complete_color,
line = list(color = toRGB("gray50"), width = 1))) %>%
add_trace(x = ~ first_per ,
marker = list(color =first_color)) %>%
add_trace(x = ~ not_vaccinated_per ,
marker = list(color = not_vaccinated_color)) %>%
layout(xaxis = list(title = "",
showgrid = TRUE,
showline = FALSE,
showticklabels = TRUE,
zeroline = TRUE,
tickwidth = 2,
tickcolor = toRGB("gray50"),
gridwidth = 2,
gridcolor = toRGB("gray50"),
side ="top",
# domain = c(0.1, 1),
ticksuffix = "%"),
yaxis = list(title = "Age Group",
# domain = c(0, 0.8),
showgrid = FALSE,
showline = FALSE,
showticklabels = TRUE,
zeroline = FALSE),
barmode = "stack",
plot_bgcolor = background,
paper_bgcolor = background,
margin = list(l = 70, t = 120, b = 60),
showlegend = FALSE) %>%
add_annotations(text = "San Francisco COVID-19 Vaccination Distribution by Age Group",
y = 1.15,
x = -0.03,
font = list(family = "Ariel",
size = 32,
color = "black"),
yref = "paper",
xref = "paper",
align = "left",
valign = "middle",
showarrow = FALSE) %>%
add_annotations(text = "Completed Two/Single Doses",
y = 0.97,
x = 0.40,
font = list(family = "Ariel",
size = font_size,
color = "white"),
yref = "paper",
xref = "paper",
align = "centar",
valign = "middle",
showarrow = FALSE) %>%
add_annotations(text = paste("First" ,"Dose", sep = "<br>"),
y = 0.988,
x = 0.765,
align = "centar",
valign = "middle",
font = list(family = "Ariel",
size = font_size,
color = "white"),
yref = "paper",
xref = "paper",
showarrow = FALSE) %>%
add_annotations(text = paste("Not", "Vaccinated", sep = "<br>"),
y = 0.988,
x = 0.905,
align = "centar",
valign = "middle",
font = list(family = "Ariel",
size = font_size,
color = "white"),
yref = "paper",
xref = "paper",
showarrow = FALSE) %>%
add_annotations(text = paste("Viz: Rami Krispin",
"Data: San Francisco Data Portal",
sep = " | "),
font = list(size = 18,
family = "Ariel"),
align = "left",
x = - 0.03,
y = - 0.07,
xref = "paper",
yref = "paper",
showarrow = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment