Chapter 8 Color Palette
library(Seurat)
library(tidyverse)
library(magrittr)
library(ArchR)
library(RColorBrewer)
8.1 Descripiton
Showing the colorpalette for heatmap and discrete clusters dimplot
8.2 Load seurat object
<- get(load('data/Demo_CombinedSeurat_SCT_Preprocess.RData')) combined
8.3 ColorPalette for heatmap
<- ArchRPalettes[16:30]
col.ls <- col.ls %>% imap( ~ {
p.ls FeaturePlot(object = combined, features = "GAD1", cols = .x) + ggtitle(label = .y)
})
<- lapply(p.ls, function(x) {
p.ls1 +
x #guides(color = FALSE, fill = FALSE) +
theme_ArchR(baseSize = 6.5, legendPosition = "right") +
theme(plot.margin = unit(c(0, 0, 0, 0), "cm")) +
theme(
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
)
})do.call(cowplot::plot_grid, c(list(ncol = 2), p.ls1[1:7]))
do.call(cowplot::plot_grid, c(list(ncol = 2), p.ls1[8:15]))
8.4 ColorPalette for discreate groups
Idents(object = combined) <- 'cluster'
<- data.frame(x = 1:20, y = 1:20)
df # archR palette
<- ArchRPalettes[1:14]
col.ls <- col.ls %>% imap(~ {
p.ls <-
g ggplot(df[1:length(.x),], aes(x, y)) + geom_point(color = .x, size = 3) + ggtitle(label = .y) +
theme_ArchR(baseSize = 6.5, legendPosition = "right") +
theme(plot.margin = unit(c(0, 0, 0, 0), "cm")) +
theme(
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank()
)return(g)
})
do.call(cowplot::plot_grid, c(list(ncol = 4), p.ls))
# the inside color assign from seurat
<- function(plot){
colorP if (!is.null(x = cols)) {
if (length(x = cols) == 1 && (is.numeric(x = cols) ||
%in% rownames(x = brewer.pal.info))) {
cols <- scale_color_brewer(palette = cols, na.value = na.value)
scale
}else if (length(x = cols) == 1 && (cols %in% c("alphabet",
"alphabet2", "glasbey", "polychrome", "stepped"))) {
<- DiscretePalette(length(unique(data[[col.by]])),
colors palette = cols)
<- scale_color_manual(values = colors, na.value = na.value)
scale
}else {
<- scale_color_manual(values = cols, na.value = na.value)
scale
}<- plot + scale
plot
}
}
# discretepalette
<- c("alphabet", "alphabet2", "glasbey", "polychrome", "stepped")
col.ls <- col.ls %>% imap( ~ {
p.ls <- DiscretePalette(n = 36, palette = .x)
cols <- data.frame(x = 1:36, y = 1:36)
df <-
g ggplot(df, aes(x, y)) +
geom_point(size = 3, color = cols) +
ggtitle(label = .x) +
theme_ArchR(baseSize = 6.5, legendPosition = "right") +
theme(plot.margin = unit(c(0, 0, 0, 0), "cm")) +
theme(
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank()
)return(g)
})
do.call(cowplot::plot_grid, c(list(ncol = 2), p.ls))
# rcolorbrew
<- 1:35 %>% imap( ~ {
p.ls <-
cols brewer.pal(name = rownames(brewer.pal.info)[.x],
n = brewer.pal.info$maxcolors[.x])
<-
g ggplot(df[1:length(cols), ], aes(x, y)) + geom_point(color = cols, size = 3) +
ggtitle(label = str_c(rownames(brewer.pal.info)[.x], " : ", brewer.pal.info$maxcolors[.x])) +
theme_ArchR(baseSize = 6.5, legendPosition = "right") +
theme(plot.margin = unit(c(0, 0, 0, 0), "cm")) +
theme(
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank()
)return(g)
})
do.call(cowplot::plot_grid, c(list(ncol = 5), p.ls))
# default color assign from seurat
<- function(n = 6, h = c(0, 360) + 15){
ggplotColours if ((diff(h) %% 360) < 1) h[2] <- h[2] - 360/n
hcl(h = (seq(h[1], h[2], length = n)), c = 100, l = 65)
}
<- ggplotColours(n=30) color_list