首页 > 解决方案 > 从 tmplot 切换到树图的简单 R 代码更新(无经验)

问题描述

我想从一个名为 REVIGO 的程序的一些给定输出结果中生成一个新的树形图。该程序提供了 R 脚本,但它已经过时(使用 tmplot 而不是树图),但我不知道如何更新它以输出树图。我对 R 的经验为零,但这是我自己制作这个数字的唯一选择。我需要更改名称的一些颜色和位置,以便它们更容易看到并且不会重叠。

我尝试查看树形图帮助功能,但由于我的知识有限,我很快就迷路了。

# A treemap R script produced by the REVIGO server at http://revigo.irb.hr/
# If you found REVIGO useful in your work, please cite the following reference:
# Supek F et al. "REVIGO summarizes and visualizes long lists of Gene Ontology
# terms" PLoS ONE 2011. doi:10.1371/journal.pone.0021800

# author: Anton Kratz <anton.kratz@gmail.com>, RIKEN Omics Science Center, Functional Genomics Technology Team, Japan
# created: Fri, Nov 02, 2012  7:25:52 PM
# last change: Fri, Nov 09, 2012  3:20:01 PM

# -----------------------------------------------------------------------------
# If you don't have the treemap package installed, uncomment the following line:
# install.packages( "treemap" );
library(treemap)                                # treemap package by Martijn Tennekes

# Set the working directory if necessary
# setwd("C:/Users/username/workingdir");

# --------------------------------------------------------------------------
# Here is your data from REVIGO. Scroll down for plot configuration options.

revigo.names <- c("term_ID","description","freqInDbPercent","abslog10pvalue","uniqueness","dispensability","representative");
revigo.data <- rbind(c("GO:0007610","behavior",3.020,22.1857,0.994,0.000,"behavior"),
c("GO:0009636","response to toxic substance",1.002,11.2504,0.969,0.000,"response to toxic substance"),
c("GO:0042493","response to drug",1.899,7.1516,0.967,0.275,"response to toxic substance"),

c("GO:0045893","positive regulation of transcription, DNA-templated",6.515,9.0725,0.754,0.670,"positive regulation of cell proliferation"),
c("GO:0050673","epithelial cell proliferation",1.733,4.2276,0.949,0.609,"positive regulation of cell proliferation"),
c("GO:0009893","positive regulation of metabolic process",14.098,8.8944,0.800,0.607,"positive regulation of cell proliferation"),
c("GO:0034645","cellular macromolecule biosynthetic process",21.549,3.0485,0.862,0.696,"positive regulation of cell proliferation"),
c("GO:0009058","biosynthetic process",26.682,3.7369,0.947,0.085,"biosynthesis"),
c("GO:0060255","regulation of macromolecule metabolic process",26.302,5.1473,0.811,0.689,"regulation of biological quality"),
c("GO:0051171","regulation of nitrogen compound metabolic process",19.403,6.6062,0.816,0.240,"regulation of biological quality"));

stuff <- data.frame(revigo.data);
names(stuff) <- revigo.names;

stuff$abslog10pvalue <- as.numeric( as.character(stuff$abslog10pvalue) );
stuff$freqInDbPercent <- as.numeric( as.character(stuff$freqInDbPercent) );
stuff$uniqueness <- as.numeric( as.character(stuff$uniqueness) );
stuff$dispensability <- as.numeric( as.character(stuff$dispensability) );

# by default, outputs to a PDF file
pdf( file="revigo_treemap.pdf", width=16, height=9 ) # width and height are in inches

# check the tmPlot command documentation for all possible parameters - there are a lot more
tmPlot(
    stuff,
    index = c("representative","description"),
    vSize = "abslog10pvalue",
    type = "categorical",
    vColor = "representative",
    title = "REVIGO Gene Ontology treemap",
    inflate.labels = FALSE,      # set this to TRUE for space-filling group labels - good for posters
    lowerbound.cex.labels = 0,   # try to draw as many labels as possible (still, some small squares may not get a label)
    bg.labels = "#CCCCCCAA",     # define background color of group labels
                                                       # "#CCCCCC00" is fully transparent, "#CCCCCCAA" is semi-transparent grey, NA is opaque
    position.legend = "none"
)

dev.off()

标签: r

解决方案


推荐阅读