zoukankan      html  css  js  c++  java
  • 答读者问(5):提取monocle2的拟时序/坐标重新画图

    之前已经讲过基于monocle2的拟时序分析,感兴趣的小伙伴可以看一下。

    今天微信群里有人问了这样一个问题:这个图上面的山脊图如何画?

    这里我给出几种简单的实现方法。还是后台回复20210812获取测试数据和代码。

    library(monocle)
    library(tidyverse)
    library(ggridges)
    library(RColorBrewer)
    library(scales)
    
    test=readRDS("test_monocle.rds")
    plotdf=pData(test)
    
    ggplot(plotdf, aes(x=Pseudotime,y=celltype,fill=celltype))+
      geom_density_ridges(scale=1) +
      geom_vline(xintercept = c(5,10),linetype=2)+
      scale_y_discrete("")+
      theme_minimal()+
      theme(
        panel.grid = element_blank()
      )
    ggsave("tmp1.pdf",width = 13,height = 7,units = "cm")
    

    ggplot(plotdf, aes(x=Pseudotime,y=celltype,fill = stat(x))) +
      geom_density_ridges_gradient(scale=1) +
      geom_vline(xintercept = c(5,10),linetype=2)+
      scale_fill_gradientn(name="Pseudotime",colors = colorRampPalette(rev(brewer.pal(10, "Spectral")))(99))+
      scale_y_discrete("")+
      theme_minimal()+
      theme(
        panel.grid = element_blank()
      )
    ggsave("tmp2.pdf",width = 13,height = 7,units = "cm")
    

    参考: https://r-charts.com/distribution/ggridges/

    类似的问题还有:如何提取坐标?

    plotdf2=as.data.frame(t(test@reducedDimS))
    colnames(plotdf2)=c("component1","component2")
    plotdf2$Pseudotime=test$Pseudotime
    
    plotdf2%>%ggplot(aes(component1,component2,color=Pseudotime))+
      geom_point()+
      theme_minimal()
    ggsave("tmp3.pdf",width = 13,height = 10,units = "cm")
    

    因水平有限,有错误的地方,欢迎批评指正!

  • 相关阅读:
    【Web技术】(一)IIS Web服务器的安装与配置
    《数据结构课程设计》图结构练习:List Component
    ExcelUtils 导表实例
    SSH整合常见错误
    mysql索引优化
    数据库三范式
    sql联接那点儿事儿
    面试java简答题
    集合类框架
    数据库连接类oracleHelper
  • 原文地址:https://www.cnblogs.com/TOP-Bio/p/15135909.html
Copyright © 2011-2022 走看看