偷偷问一下,关注了吗?
内容获取
1、购买打包合集(《KS科研分享与服务》付费内容打包集合),价格感人,可以加入微信VIP群(答疑交流群,甚至有小伙伴觉得群比代码更好),可以获取建号以来所有内容,群成员专享视频教程,提前更新,其他更多福利!
2、《KS科研分享与服务》公众号有QQ群,进入门槛是20元(完全是为了防止白嫖党,请理解),请考虑清楚。群里有免费推文的注释代码和示例数据(终身拥有),没有付费内容,群成员福利是购买单个付费内容半价!
需要者详情请联系作者(非需要者勿扰,处理太费时间):
setwd('D:\\KS项目\\公众号文章\\cpdb结果可视化之-气泡图-弦图')
df <- read.csv('./cpdb_pbmc_summary.txt', header = T, sep = '\t', row.names = 1)
# plot dotplot ------------------------------------------------------------
#提取需要的互作
# unique(df$celltype_pair)
df_sce <- df[df$celltype_pair %in% c("B|B","B|CD14 Monocytes","B|CD4 T","B|CD8 T","B|Dendritic",
"B|FCGR3A Monocytes","B|NK","B|FCGR3A Monocytes"),]
#筛选显著的互作
df_sce <- df_sce[df_sce$pval <=0.05,]
colnames(df)
# [1] "interacting_pair" "celltype_pair" "mean" "pval"
library(ggplot2)
#ggplot作图
ggplot(df_sce, aes(x=celltype_pair, y=interacting_pair,
size= -log10(pval+0.001), color=mean)) +
geom_point(stat = "identity")+
geom_point(aes(size= -log10(pval+0.001)), shape = 21, colour="black", stroke=1)+
theme_bw()+
scale_y_discrete(limits=rev)+
scale_fill_viridis_c(option = "magma", guide = "colourbar", aesthetics = "color", direction=-1)+
theme(axis.text.x = element_text(size = 10, angle=45, hjust=1, vjust=1, colour = 'black'),
axis.text.y = element_text(size = 10, colour = 'black'),
axis.title.x = element_text(face='bold', size=12),
axis.title.y = element_text(face='bold', size=12))+
xlab("Cell_pair") + ylab("ligand_receptor pair")
# plot circle -------------------------------------------------------------
library(tidyr)
library(dplyr)
library(iTALK)
library(circlize)
# circle_plot1 ------------------------------------------------------------
#挑选显著互作
df_sig <- df[df$pval <=0.05 & df$mean >= 2,]
df_sig <- df_sig %>% separate(celltype_pair, c("source", "target"), "\\|")
df_sig <- df_sig %>% separate(interacting_pair, into = c("ligand", "receptor"), sep = "_", extra = "merge")
#可以选择自己需要展示的受配体展示,挑选数据即可
#这里我直接按照mean排序,选择前40可视化
df_sig <- df_sig[order(-df_sig$mean),]
df_sig_plot <- df_sig[1:40,]
# colnames(df_sig)[3] <- "cell_from"
# colnames(df_sig)[4] <- "cell_to"
#
#
# df_sig <- df_sig %>%
# select(1:2, cell_from_mean_exprs = 3, 4:ncol(.)) %>%
# mutate(cell_from_mean_exprs = df_sig$mean)
#
#
# df_sig <- df_sig %>%
# select(1:2, cell_from_mean_exprs = 3, 4:ncol(.)) %>%
# mutate(cell_from_mean_exprs = df_sig$mean)
#设置颜色
gene_col<-structure(c(rep('#CC3333',length(df_sig_plot$ligand)),
rep("#006699",length(df_sig_plot$receptor))),
names=c(df_sig_plot$ligand,df_sig_plot$receptor))
cell_col <- structure(c("#d2981a", "#a53e1f", "#457277", "#8f657d", "#42819F", "#86AA7D", "#CBB396"),
names=unique(df_sig_plot$source))#设置细胞颜色
#弦图连线体现source cell,link_cols = T,不设置link.arr.col
ks_iTALK_LRPlot(df_sig_plot,#挑选前40作图
link_cols = T,
link.arr.lwd=df_sig_plot$mean,
link.arr.width=0.1,
link.arr.type = "triangle",
link.arr.length = 0.1,
# link.arr.col = alpha("#47B9B5",0.4),#连线颜色设置
print.cell = T,
track.height_1=uh(5, "mm"),
track.height_2 = uh(10, "mm"),
annotation.height_1=0.02,
annotation.height_2=0.02,
text.vjust = "0.1cm",
gene_col = gene_col,
cell_col = cell_col)
#弦图连线不体现source cell,link_cols = F,设置link.arr.col
ks_iTALK_LRPlot(df_sig_plot,#挑选前40作图
link_cols = F,
link.arr.lwd=df_sig_plot$mean,
link.arr.width=0.1,
link.arr.type = "triangle",
link.arr.length = 0.1,
link.arr.col = alpha("#47B9B5",0.4),#连线颜色设置
print.cell = T,
track.height_1=uh(5, "mm"),
track.height_2 = uh(10, "mm"),
annotation.height_1=0.02,
annotation.height_2=0.02,
text.vjust = "0.1cm",
gene_col = gene_col,
cell_col = cell_col)
# circle_plot2 ------------------------------------------------------------
#挑选自己感兴趣的细胞进行可视化,选择显著的互作
df_sig <- df[df$pval <=0.05,]
cell_inter = c('NK|CD14 Monocytes', 'NK|FCGR3A Monocytes')
LR = c('CD1D_LILRB2', 'CD44_TYROBP', 'CD48_CD244',"HLA-F_KIR3DL2")
ks_comm_chordDiagram(data = df_sig,
cell_inter = cell_inter,
LR=LR,
group=c("NK"='#0c0459',
"CD14 Monocytes"='#F09709',
"FCGR3A Monocytes"='#47B9B5'),
text_size=0.8)
觉得我们分享有些用的,点个赞再走呗!
关注我们获取精彩内容:
关注不迷路:扫描下面二维码关注公众号!
B站视频号链接:https://space.bilibili.com/471040659?spm_id_from=333.1007.0.0
关注 KS科研分享与服务,
认清正版优质内容和服务!
优质内容持续输出,物超所值!
合作联系:ks_account@163.com