Skip to content

Instantly share code, notes, and snippets.

@stemangiola
Last active July 28, 2023 04:27
Show Gist options
  • Save stemangiola/cfa08c45c28fdf223d4996a6c1256a39 to your computer and use it in GitHub Desktop.
Save stemangiola/cfa08c45c28fdf223d4996a6c1256a39 to your computer and use it in GitHub Desktop.
Color cell types
get_cell_type_color = function(cell_type_vector){
cell_type_vector |>
enframe(value = "harmonised_cell_type") |>
left_join(
tribble(
~harmonised_cell_type, ~palette,
# B
'b memory', "Purples",
'b naive', "Purples",
'plasma', "Purples",
'pdc', "Purples",
# Mono
'cd14 mono', "Blues",
'cd16 mono', "Blues",
'cdc', "Blues",
'macrophage', "Blues",
# T
'tregs', "Reds",
'treg', "Reds",
'cd4', "Reds",
'cd8', "Reds",
'cd4 naive', "Reds",
'cd4 tcm', "Reds",
'cd4 tem', "Reds",
"cd4 fh" , "Reds",
"cd4 th1" , "Reds",
"cd4 th1/th17" , "Reds",
"cd4 th17" , "Reds",
"cd4 th2", "Reds",
"cd4 term eff", "Reds",
"terminal effector cd4 t", "Reds",
# T cytotoxic
'cd8 naive', "Oranges",
'cd8 tcm', "Oranges",
'cd8 tem', "Oranges",
'mait', "Oranges",
'tgd', "Oranges",
# Other
'nk', "Greens",
'ilc', "Greens",
'non_immune', "Greys",
'stem', "Greys",
'mast', "Greys",
NA, "Greys"
),
by = join_by(harmonised_cell_type)
) |>
tidyr::replace_na(list(palette = "Greys")) |>
nest(data = -palette) |>
mutate(color = map2(palette, data, ~ RColorBrewer::brewer.pal(max(nrow(.y), 3), .x)[1:nrow(.y)] )) |>
unnest(c(data, color)) |>
dplyr::select(harmonised_cell_type, color ) |>
deframe()
}
color_array =
tibble(
harmonised_cell_type = c('b memory', 'b naive', 'plasma', 'cd14 mono', 'cd16 mono', 'treg', 'mait', 'tgd', 'cd4', 'cd8', 'cd4 naive', 'cd4 tcm', 'cd4 tem', 'cd8 naive', 'cd8 tcm', 'cd8 tem', 'cdc', 'immune_unclassified', 'macrophage', 'mast', 'nk', 'ilc', 'non_immune', 'pdc', 'stem', 'treg', NA)
) |>
mutate(palette = c("Purples", "Purples", "Purples", "Blues", "Blues", "Reds", "Reds", "Reds", "Reds", "Reds", "Reds", "Reds", "Reds", "Reds", "Reds", "Reds", "Blues", "Greys", "Blues", "Greys", "Greens", "Greens", "Greys", "Blues", "Greys", "Reds", "Greys")) |>
nest(data = -palette) |>
mutate(color = map2(palette, data, ~ RColorBrewer::brewer.pal(max(nrow(.y), 3), .x)[1:nrow(.y)] )) |>
unnest(c(data, color)) |>
dplyr::select(harmonised_cell_type, color ) |>
deframe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment