UMAP
umap <- read_rds("/volumes/USR1/yyan/project/tnbc_pre_atlas/deliver/atlas_20251023_share/umap.rds")
scattermore::scattermoreplot(umap[, 1], umap[, 2], asp=1)

for (col in col_cat) {
col_lv <- sort(unique(as.character(df[, col])))
pal_col <- structure(rainbow(n=length(col_lv)), names=col_lv)
scattermore::scattermoreplot(
umap[, 1], umap[, 2], col = pal_col[as.character(df[, col])],
asp=1, main=col)
}



# col <- 'cellstate'
# col_lv <- sort(unique(as.character(df[, col])))
# pal_col <- structure(rainbow(n=length(col_lv)), names=col_lv)
#
# for (col_lv_x in col_lv) {
# idx <- as.character(df[, col]) %in% col_lv_x
# scattermore::scattermoreplot(
# umap[, 1], umap[, 2],
# col = ifelse(idx, pal_col[as.character(df[, col])][col_lv_x], 'grey'),
# asp=1, main=sprintf('%s: %d cells', col_lv_x, sum(idx)))
# }
Gene expression
data <- read_rds('/volumes/USR1/yyan/project/tnbc_pre_atlas/deliver/atlas_20251023_share/mat_data.rds')
print(dim(data))
## [1] 33538 427857
library(colorspace)
library(ggpubr)
query_gene <- "EPCAM"
v <- data[query_gene, ]
dfv <- data.frame(cbind(umap, v))
set.seed(42)
idx <- sample(1:nrow(dfv), size=nrow(dfv))
dfv <- dfv[idx, ]
head(dfv)
## UMAP_1 UMAP_2 v
## Mye_ARTC23_ACTATGGAGGTCATTC -11.140078 9.4080937 0.000000
## B_ARTC20_TCAGTTTGTAGTGATA -2.160829 6.6423953 0.000000
## T_ARTC31_TGAGGAGCAGTAGAAT -1.433794 -0.2171205 0.000000
## Mye_ARTC27_ACGTAACAGGTCATTC -9.071169 7.3530205 0.000000
## B_ARTC18_CAGGGCTCATGCAGCC 5.107306 8.8766730 0.434959
## Tumor_ARTC102_CCCTTAGGTCAACATC-1 7.476499 2.8980523 1.898505
theme_set(theme_void())
ggplot(dfv, aes(x=UMAP_1, y=UMAP_2, color=v)) +
geom_scattermore() +
colorspace::scale_color_continuous_sequential(palette = 'Reds 3')+
labs(color=query_gene)+
coord_equal() + ggpubr::border()+
theme(legend.position = 'top', aspect.ratio = 1)
## Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## ℹ The deprecated feature was likely used in the ggpubr package.
## Please report the issue at <https://github.com/kassambara/ggpubr/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

gene_opts <- c(
'EPCAM',
'LYZ', 'LILRA4', 'TPSAB1',
'TRAC', 'CD3D', 'NKG7', 'GNLY',
'CD79A', 'MS4A1',
'FAP', 'COL1A1',
'VWF',
'RGS5', 'SYNPO2'
)
p_list <- list()
theme_set(theme_pubr())
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## ℹ The deprecated feature was likely used in the ggpubr package.
## Please report the issue at <https://github.com/kassambara/ggpubr/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
set.seed(42)
idx <- sample(1:nrow(umap), size=nrow(umap))
for (g in gene_opts) {
message(g)
v <- data[g, ]
dfv <- data.frame(cbind(umap, v))
dfv <- dfv[idx, ]
head(dfv)
p_g <- ggplot(dfv, aes(x=UMAP_1, y=UMAP_2, color=v)) +
geom_scattermore() +
# colorspace::scale_color_continuous_sequential(palette = 'Reds 3')+
# scale_color_viridis_c(option='E') +
scale_color_gradient(low = 'snow2', high = 'purple4') +
labs(color='', title = g)+
coord_equal() + ggpubr::border()+
theme(legend.position = 'right', aspect.ratio = 1,
legend.key.width = unit(1, "lines"),
legend.key.height = unit(1, "lines")) +
ggpubr::rremove('x.title') + rremove('y.title') +
rremove('x.ticks') + rremove('y.ticks') + rremove('x.text') + rremove('y.text')
# p_g
p_list <- c(p_list, list(p_g))
}
## EPCAM
## LYZ
## LILRA4
## TPSAB1
## TRAC
## CD3D
## NKG7
## GNLY
## CD79A
## MS4A1
## FAP
## COL1A1
## VWF
## RGS5
## SYNPO2
p_list0 <- p_list
p_list <- lapply(p_list, function(x) {
x + theme(legend.key.width = unit(.5, "lines"))
})
length(gene_opts)
## [1] 15
p <- ggpubr::ggarrange(plotlist=p_list, ncol=3)
print(p)
## $`1`

##
## $`2`

##
## $`3`

##
## $`4`

##
## $`5`

##
## attr(,"class")
## [1] "list" "ggarrange"