答读者问(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")

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

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值