偷偷问一下,关注了吗?
内容获取
1、购买打包合集(《KS科研分享与服务》付费内容打包集合),价格感人,可以加入微信VIP群(答疑交流群,甚至有小伙伴觉得群比代码更好),可以获取建号以来所有内容,群成员专享视频教程,提前更新,其他更多福利!
2、《KS科研分享与服务》公众号有QQ群,进入门槛是20元(完全是为了防止白嫖党,请理解),请考虑清楚。群里有免费推文的注释代码和示例数据(终身拥有),没有付费内容,群成员福利是购买单个付费内容半价!
需要者详情请联系作者(非需要者勿扰,处理太费时间):
setwd('D:\\KS项目\\公众号文章\\单细胞marker基因密度图')
library(Seurat)
library(Nebulosa)
library(ggnetwork)
library(dplyr)
markers <- FindAllMarkers(mouse_data, logfc.threshold = 0.5, min.pct = 0.5)
markers_plot <- markers %>%
group_by(cluster) %>%
slice(1:2)
plot_density(mouse_data, features = c("Ltf"),
pal = 'magma', raster = T, size = 0.8) &
theme_blank()&#这个是ggnetwork里面的主题,可以去掉所有ggplot背景
theme(legend.frame = element_rect(colour = "black"),
legend.ticks = element_line(colour = "black", linewidth = 0),
legend.key.width = unit(0.3, "cm"),
legend.key.height = unit(0.8, "cm"),
legend.title = element_text(color = 'black', face = "bold", size=8))
plot_density(mouse_data, features = c("Ltf"),
pal = 'magma', raster = T, size = 0.8) &
theme_blank()&
theme(panel.background = element_rect(fill = "black"))&
theme(legend.frame = element_rect(colour = "black"),
legend.ticks = element_line(colour = "black", linewidth = 0),
legend.key.width = unit(0.3, "cm"),
legend.key.height = unit(0.8, "cm"),
legend.title = element_text(color = 'black', face = "bold", size=8))
###批量作图
plist <- list()
for (i in 1:nrow(markers_plot)) {
p = plot_density(mouse_data, features = markers_plot$gene[i],
pal = 'magma', raster = F, size = 0.8) &
theme_blank()&
theme(legend.frame = element_rect(colour = "black"),
legend.ticks = element_line(colour = "black", linewidth = 0),
legend.key.width = unit(0.3, "cm"),
legend.key.height = unit(0.6, "cm"),
legend.title = element_text(color = 'black', face = "bold", size=8))
plist[[i]] <- p
}
#拼图
library(cowplot)
plot_grid(plotlist = plist, ncol = 4)
plist1 <- list()
for (i in 1:nrow(markers_plot)) {
p = plot_density(mouse_data, features = markers_plot$gene[i],
pal = 'magma', raster = F, size = 0.8) &
theme_blank()&
theme(panel.background = element_rect(fill = "black"))&
theme(legend.frame = element_rect(colour = "black"),
legend.ticks = element_line(colour = "black", linewidth = 0),
legend.key.width = unit(0.8, "cm"),
legend.key.height = unit(0.3, "cm"),
legend.title = element_text(color = 'black', face = "bold", size=8))&
theme(plot.title = element_blank())&
theme(legend.position = "top")&
annotate("text", x = 0, y = Inf,
label = markers_plot$gene[i], vjust = 1.5,
size = 6, color='white')
plist1[[i]] <- p
}
#拼图
library(cowplot)
plot_grid(plotlist = plist1, ncol = 4)
library(ggunchull)
plot_density(mouse_data, features = c("Ltf"),
pal = 'magma', raster = T, size = 0.8) &
theme_blank()&
theme(panel.background = element_rect(fill = "black"))&
theme(legend.frame = element_rect(colour = "black"),
legend.ticks = element_line(colour = "black", linewidth = 0),
legend.key.width = unit(0.3, "cm"),
legend.key.height = unit(0.8, "cm"),
legend.title = element_text(color = 'black', face = "bold", size=8))&
theme(plot.title = element_blank())&
annotate("text", x = 0, y = Inf,
label = "Ltf", vjust = 1.5,
size = 6, color='white')&
stat_unchull(alpha=0.25,
size=0.25,lty=2,
color='white',
nbin = 400,
nsm = 5,
qval = 0.8,
sfac = 1.4)
single_CM_density(object = mouse_data,
features = "Ltf",
night = T)
#2黑夜模式,只选择需要的celltype,我这里选择PMN(7),聚类好
#设置这个模式,需要设置参数idents
single_CM_density(object = mouse_data,
features = "Ltf",
night = T,
idents = "celltype",
label_celltype = "PMN(7)")
#正常模式
#unchull=F,不需要框线
single_CM_density(object = mouse_data,
features = "Ltf",
night = F)
#unchull=T,需要框线
single_CM_density(object = mouse_data,
features = "Ltf",
night = F,
unchull = T)
#批量出图
plist2 <- list()
for (i in 1:nrow(markers_plot)) {
p = single_CM_density(object = mouse_data,
features = markers_plot$gene[i],
night = T)
plist2[[i]] <- p
}
#拼图
library(cowplot)
plot_grid(plotlist = plist2, ncol = 4)
觉得我们分享有些用的,点个赞再走呗!
关注我们获取精彩内容:
关注不迷路:扫描下面二维码关注公众号!
B站视频号链接:https://space.bilibili.com/471040659?spm_id_from=333.1007.0.0
关注 KS科研分享与服务,
认清正版优质内容和服务!
优质内容持续输出,物超所值!
合作联系:ks_account@163.com