Я работаю над древовидной картой, которая является выходом с сайта REVIGO.
Я хотел бы определить цвет для каждого "репрезентативного" термина, чтобы я мог сохранить его на нескольких картах, которые мне нужныпроизводить.например, красный, транспортный синий ... или любой другой способ, который позволяет мне сохранять одинаковые цвета для одной и той же метки столбца «представитель».
Вот сценарий.
Я совсем новичок в R, любая помощь высоко ценится!
# 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","value","uniqueness","dispensability","representative");
revigo.data <- rbind(c("GO:0000003","reproduction",0.769,13.0000,1.000,0.000,"reproduction"),
c("GO:0006810","transport",17.616,38.0000,0.958,0.000,"transport"),
c("GO:0006950","response to stress",4.575,48.0000,0.799,0.000,"response to stress"),
c("GO:0009991","response to extracellular stimulus",0.473,5.0000,0.811,0.438,"response to stress"),
c("GO:0009628","response to abiotic stimulus",0.571,19.0000,0.824,0.448,"response to stress"),
c("GO:0007165","signal transduction",6.621,28.0000,0.676,0.637,"response to stress"),
c("GO:0009607","response to biotic stimulus",0.342,14.0000,0.829,0.421,"response to stress"),
c("GO:0009605","response to external stimulus",1.370,27.0000,0.814,0.501,"response to stress"),
c("GO:0009606","tropism",0.006,1.0000,0.845,0.561,"response to stress"),
c("GO:0009719","response to endogenous stimulus",0.526,15.0000,0.825,0.443,"response to stress"),
c("GO:0007275","multicellular organism development",1.559,49.0000,0.708,0.000,"multicellular organism development"),
c("GO:0006412","translation",5.686,10.0000,0.831,0.614,"multicellular organism development"),
c("GO:0007267","cell-cell signaling",0.407,4.0000,0.841,0.197,"multicellular organism development"),
c("GO:0009908","flower development",0.030,1.0000,0.757,0.640,"multicellular organism development"),
c("GO:0040029","regulation of gene expression, epigenetic",0.130,2.0000,0.882,0.229,"multicellular organism development"),
c("GO:0005975","carbohydrate metabolic process",5.260,6.0000,0.913,0.134,"multicellular organism development"),
c("GO:0019748","secondary metabolic process",0.138,2.0000,0.896,0.158,"multicellular organism development"),
c("GO:0019538","protein metabolic process",18.489,38.0000,0.888,0.191,"multicellular organism development"),
c("GO:0006259","DNA metabolic process",5.607,14.0000,0.852,0.407,"multicellular organism development"),
c("GO:0006464","cellular protein modification process",7.726,21.0000,0.845,0.265,"multicellular organism development"),
c("GO:0019725","cellular homeostasis",1.253,5.0000,0.834,0.224,"multicellular organism development"),
c("GO:0007049","cell cycle",1.885,24.0000,0.853,0.100,"multicellular organism development"),
c("GO:0006139","nucleobase-containing compound metabolic process",26.547,49.0000,0.856,0.123,"multicellular organism development"),
c("GO:0006629","lipid metabolic process",3.522,16.0000,0.855,0.112,"multicellular organism development"),
c("GO:0008219","cell death",0.458,9.0000,0.864,0.200,"multicellular organism development"),
c("GO:0016049","cell growth",0.153,2.0000,0.872,0.179,"multicellular organism development"),
c("GO:0009856","pollination",0.044,1.0000,0.839,0.614,"multicellular organism development"),
c("GO:0007610","behavior",0.170,3.0000,0.949,0.000,"behavior"),
c("GO:0008152","metabolic process",75.387,149.0000,0.987,0.000,"metabolism"),
c("GO:0009056","catabolic process",4.820,27.0000,0.939,0.000,"catabolism"),
c("GO:0009987","cellular process",63.780,324.0000,0.982,0.000,"cellular process"),
c("GO:0040007","growth",0.317,4.0000,0.950,0.000,"growth"),
c("GO:0006091","generation of precursor metabolites and energy",1.940,1.0000,0.907,0.020,"generation of precursor metabolites and energy"),
c("GO:0009058","biosynthetic process",31.611,64.0000,0.947,0.033,"biosynthesis"),
c("GO:0016043","cellular component organization",7.239,76.0000,0.919,0.050,"cellular component organization"),
c("GO:0007154","cell communication",7.219,33.0000,0.919,0.062,"cell communication"));
stuff <- data.frame(revigo.data);
names(stuff) <- revigo.names;
stuff$value <- as.numeric( as.character(stuff$value) );
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_biological_process_subcluster2_drop.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
treemap(
stuff,
index = c("representative","description"),
vSize = "value",
type = "categorical",
vColor = "representative",
title = "",
inflate.labels = FALSE,
drop.unused.levels = 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 = "#CCCCCC00", # define background color of group labels
# "#CCCCCC00" is fully transparent, "#CCCCCCAA" is semi-transparent grey, NA is opaque
position.legend = "none"
)
dev.off()