jj_get_colours: get colours as named vector from file

View source: R/jj_get_colours.R

jj_get_coloursR Documentation

get colours as named vector from file

Description

get colours as named vector from file

Usage

jj_get_colours(
  annotation_vector = NULL,
  colour_csv,
  plot_colours = FALSE,
  comment_char = "/"
)

Arguments

annotation_vector

vector with the groups for which colours are needed

colour_csv

two column csv with annotation in first column and colour in second column (alternatively a data.frame with columns group and colour or a named vector of colours)

plot_colours

visualize colours as ggplot heatmap, default = FALSE

comment_char

Lines in the colour file starting with this character are ignored, default = '/'

Examples

#Save colour mapping in file (may contain comment lines starting with `/`)
colour_df  = data.frame(group= c('g1','g2','g3'),colour= c('yellow', 'darkred','#D7B5D8'))
write.table(colour_df, file = 'colour_map.csv',
            sep = ',', row.names = F, col.names=F)
# just show the colours in the file (also works passing the data.frame)
jj_get_colours(colour_csv='colour_map.csv', plot_colours=TRUE)
jj_get_colours(colour_csv=colour_df, plot_colours=TRUE)
# use the colours in ggplot (automatically selects the groups which are needed)
custom_cols = jj_get_colours(pbmc_small$groups, colour_csv='colour_map.csv')
Seurat::DimPlot(pbmc_small,  group.by = 'groups') + scale_colour_manual(values=custom_cols)
#or using jj_plot_features
jj_plot_features(pbmc_small, reduction='tsne', meta_features='groups', custom_colors = custom_cols, pt.size = 3)

mathosi/jj documentation built on Feb. 25, 2024, 2:29 p.m.