R图显示突变 [英] R plot to show mutation

查看:50
本文介绍了R图显示突变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 R 新手.我想画这样的图(左下部分):http://www.nature.com/ng/journal/v45/n8/images_article/ng.2699-F3.jpg,

I'm new in R. I'd like to draw figures like this (lower left part): http://www.nature.com/ng/journal/v45/n8/images_article/ng.2699-F3.jpg,

显示突变的共存或排除(每行一个基因,每列一个样本).我不认为它是由热图或地图.这是一个样本数据(1 表示突变,0 表示野生型,NA 表示不可用):

to show the co-existing or exclusive of mutations (one gene per line and one sample per column). I don't think it's plotted by heatmap or pheatmap. And here is a sample data (1 for mutation, 0 for wildtype and NA for not available):

data=matrix(sample(c(rep(0,30),rep(1,30)),60),ncol=15)
is.na(data)=c(2,20)

关于如何完成的任何建议?谢谢~

Any suggestions on how to finish that? Thanks~

推荐答案

这在我看来就像光栅/平铺图形.有几种选择.我个人认为 ggplot2 包做得很好.

This looks like raster/tiling graphics to me. There are several options. Personally I think the ggplot2 package does a good job.

但是,我没有使用您提供的示例,因为我认为最好以长格式组织数据.有关如何执行此操作的简单示例,请参阅下面的代码:

I didn't use your provided example, however, because I think the data would best be organized in a long format. See code below for a simple example on how to do this:

require(ggplot2)

dat <- expand.grid(gene=1:10, subj=1:50)
dat$mut <- as.factor(sample(c(rep(0,300),rep(1,200)),500))
dat$mut[sample(500,300)] <- NA

ggplot(dat, aes(x=subj, y=gene, fill=mut)) + 
  geom_raster() +
  scale_fill_manual(values = c("#8D1E0B","#323D8D"), na.value="#FFFFFF")

#dev.off()

可以使用手动比例尺和 ggplot2 提供的主题功能优化视觉外观.您可以在包的文档中查找:http://docs.ggplot2.org/current/

The visual appearance can be optimized using the manual scales and the theming functions provided by ggplot2. You can look that up in the documentation of the package: http://docs.ggplot2.org/current/

详细说明 ggplot2 提供的用于自定义外观的选项.具有自定义外观和比例的更清晰的绘图变体可能如下所示:

To elaborate a bit more on the options that are supplied by ggplot2 to customoize appearance. A cleaner variant of the plot, with customized appearance and scales, may look like this:

ggplot(dat, aes(x=subj, y=gene, fill=mut)) +
  geom_raster() +
  scale_fill_manual(values = c("#8D1E0B","#323D8D"), na.value="#FFFFFF") +
  scale_x_discrete("Subject") +
  scale_y_continuous(breaks=1:10,
    labels=c("D0","D1","D2","D3","D4","D5","D6","D7","D8","D9")) +
  guides(fill=FALSE) +
  theme(
    axis.ticks.x=element_blank(), axis.ticks.y=element_blank(),
    axis.text.x=element_blank(), axis.text.y=element_text(colour="#000000"), 
    axis.title.x=element_text(face="bold"), axis.title.y=element_blank(),
    panel.grid.major.x=element_blank(), panel.grid.major.y=element_blank(),
    panel.grid.minor.x=element_blank(), panel.grid.minor.y=element_blank(), 
    panel.background=element_rect(fill="#ffffff")
  )

#dev.off()

尽管如此,查看 ggplot2 的文档对于开发图形并根据需要进行调整非常有用.

Nonetheless, a look into the documentation of ggplot2 is very useful in developing your graphics and adjusting them to your needs.

这篇关于R图显示突变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆