Created
February 7, 2020 23:43
-
-
Save Tadge-Analytics/e79e3f6d406b40f2b18fbb5c44a35bf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) | |
library(tidyverse) | |
library(kableExtra) | |
formatted_Values <- tibble::tribble( | |
~Metric, ~BAKER, ~OREGON, ~RURAL, ~URBAN, | |
"Food insecurity", "15%", "13%", NA, NA, | |
"Child Poverty", "23%", "19%", "18%", "20%", | |
"Foster care rate (per 1,000 population)", "33", "13", "21", "11", | |
"Index crime (per 1,000 population)", "20", "30", "20", "32", | |
"Voter participation", "72%", "70%", NA, NA | |
) | |
image_path <- "kable styling package.PNG" | |
magick::image_read(image_path) | |
# aspects | |
# 1 - no boarder between categories | |
# 2 - no "Metric" header -add cummumity in post | |
# 3 - BAKER is yellow + bold | |
# 4 - NA is white and blank | |
# 5 - all numbers are centred | |
# 6 - some cells are darker or lighter green if they are bigger or smaller or white if they are the same. | |
# 7 - set the main columns to be equal width | |
formatted_Values %>% | |
mutate_at(.vars = vars(OREGON, RURAL, URBAN), | |
.funs = list(~ replace_na(., ""))) %>% | |
rename(Community = 1) %>% | |
mutate_at(.vars = vars(OREGON, RURAL, URBAN), | |
.funs = list(~ cell_spec(., | |
"html", | |
background_as_tile = F, | |
background = | |
case_when(parse_number(.) > parse_number(BAKER) ~ "red", | |
parse_number(.) < parse_number(BAKER) ~ "blue", | |
TRUE ~ "white")))) %>% | |
kable(escape = F) %>% | |
kable_styling( | |
full_width = F, | |
position = "left" | |
) %>% | |
column_spec(1, | |
extra_css = "text-align: right;" , | |
include_thead = F) %>% | |
column_spec(2, | |
background = "Yellow", | |
include_thead = T) %>% | |
column_spec(2:5, | |
extra_css = "border: 1px solid #000000; text-align: center;", | |
include_thead = T) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment