单细胞 | 可视化基因表达水平 云雨图:gghalves 包 左边散点,右边小提琴图

21 篇文章 0 订阅
8 篇文章 0 订阅

1.效果图

Fig1

由于大量0值,导致小提琴图不好看,** 下面2个图做了过滤,只保留>1e-4的点 **。这样是否合适,还有待探讨 //todo
Fig2
Fig3

2.源码

三个图

  • Seurat 函数 VlnPlot
  • 从ggplot2获取数据,重新绘制 violin plot
  • 使用 gghalves 包 左边散点,右边小提琴图
scObj$tissue.type=factor(scObj$tissue.type, 
                         levels = c("NL", "LP",  'CA',    'LN'))


### (3)Re plot half VlnPlot ----
gene.symbol="PCF11"
g2=VlnPlot(scObj, 
           features = c(gene.symbol),
           #features = c("CD68"), 
        #group.by="tissue.type", 
        group.by="cell.type", 
        #cols = color.head,
        pt.size=0)+RotatedAxis(); g2 #fig1
#  scale_color_manual(color.head)
head(g2$data)
#                           PCF11 ident
#AAACGGGCATGACGGA-1  1.370958e-05         T.cells
#AAAGATGAGCAGACTG-1 -5.646982e-06         T.cells


# BiocManager::install("gghalves")
# options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor") 
# options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
library(gghalves)
dat=data.frame(
  ident=g2$data$ident,
  value=g2$data[,1]
)
# rm 0 values?
dim(dat)
dat=dat[which(dat$value>1e-4),]
dim(dat)
ggplot(dat, aes(x = ident, y = value, fill = ident) )+
  geom_jitter(size=0.1, color="grey80") +
  geom_violin(trim=F, #末尾是否截断
              aes(fill=ident), #填充颜色
              scale="width", #默认是按面积 area,推荐改为width
              bw=0.1)+ #取样宽度,越小越精细模拟原始值
  geom_boxplot(width=0.1, fill="white", show.legend = F, 
               outlier.colour = "#00000000") + #离群值 透明
  theme_classic(base_size = 14)+
  RotatedAxis()+
  ggtitle(gene.symbol) #fig2
#

ggplot(dat, aes(x = ident, y = value, fill = ident) ) +
  geom_half_point(size=0.1, side="l", aes(color=ident) )+
  geom_half_violin(
    aes(fill = ident),
    alpha=0.7,
    #position = position_nudge(x = .15, y = 0),
    #adjust=0.5,
    trim=F, 
    colour=NA, #描边颜色
    bw=0.1,
    side = 'r',
    show.legend = F
  )+
  geom_boxplot(width=0.1, fill="white", show.legend = F, 
               outlier.colour = "#00000000") + #离群值 透明
  #scale_fill_manual(values = color.head) +
  #scale_color_manual(values = color.head) +
  theme_classic(base_size = 14)+
  RotatedAxis()+
  labs(x="", y="log(Normalized counts +1)", title = bquote( italic(.(gene.symbol)) ) )+
  guides(colour = guide_legend(override.aes = list(alpha = 1, size=3))) #fig3
#                         

水平图

参考:
# 旋转坐标
ggplot2::ggplot(iris , aes(x = Species, y = Sepal.Length, fill = Species))+ 
              gghalves::geom_half_violin(aes(fill = Species),  
                                             position = position_nudge(x = .15, y = 0),
                                             adjust=1.5, trim=FALSE,                           
                                             colour=NA, side = 'r') +              
              gghalves::geom_half_dotplot(aes(fill = Species), method="histodot", stackdir="down",  
                                          dotsize = 0.55, position=position_nudge(x = .15, y = 0),               
                                          binwidth = 0.15, colour = NA   
                                          ) +               
              ggplot2::coord_flip() +              
              ggthemes::theme_base()

ref

  • https://www.jianshu.com/p/f9adedcfc71c
  • https://zhuanlan.zhihu.com/p/617212689
  • https://www.bilibili.com/read/cv12815285/
  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值