原文地址:https://mp.weixin.qq.com/s/cFX51WjlgS-SetbM8THqdg
首先還是講一下配置文件的準備(這也是你唯一需要操心的地方了)披诗。
這一次配置文件分為兩個txt文檔,分別存有上調(diào)和下調(diào)基因的GO富集結(jié)果壮莹,數(shù)據(jù)格式如下圖所示:
左邊是上調(diào)基因GO富集的結(jié)果,右邊是下調(diào)基因GO富集的結(jié)果,每邊1-4列分別是GO
terms, Gene number,
-log10(P-value)和fill(即第一行,作為列名)资盅,我是按的-log10(P-value)排序,選的top20的結(jié)果踊赠,這個可以自己定(但不要太多呵扛,比如top100。筐带。今穿。)(如果你想按照gene
number排序,只需要將第二列和第三列互換一下位置就好了伦籍,最后有演示)
顏色的選擇建議使用http://colorbrewer2.org選擇蓝晒,具體使用方法如下:
在excel中編輯好文檔后腮出,將上下調(diào)基因GO富集結(jié)果分別復(fù)制粘貼到兩個txt文檔中,分別命名為up.txt芝薇,down.txt
保存好后利诺,在同一目錄下新建一個文本文檔,將文末的代碼復(fù)制粘貼到里面剩燥,保存慢逾,更改文件名為GO.R
然后右鍵,用R-studio打開灭红,全選侣滩,Run
然后在同一目錄下會生成一個GO.svg的文件,可以用Inkscape或者AI打開变擒,直接另存為PDF即可君珠。
然后,你就得到矢量圖了
我是取得top20的娇斑,這個可以自己根據(jù)需要選擇策添,比如我按基因數(shù)目排序選top15,換另外一種色系顏色毫缆,只需要修改配置文件就好了唯竹,不需要更改代碼(知識點:配置文件是關(guān)鍵)。
R腳本:
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Author: Zhaodong Hao
# Create data: 2017-06-24
# Description: GO enrichment - 2
# Attention: you can use Inkscape or AI to open the output file (.svg) and save as a PDF file
# Contact: haozd1992@163.com
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# set the working dictionary as the path of 'source'd file
whereFrom=sys.calls()[[1]]
# This should be an expression that looks something like
# source("pathname/myfilename.R")
whereFrom=as.character(whereFrom[2]) # get the pathname/filename
whereFrom=paste(getwd(),whereFrom,sep="/") # prefix it with the current working directory
pathnameIndex=gregexpr(".*/",whereFrom) # we want the string up to the final '/'
pathnameLength=attr(pathnameIndex[[1]],"match.length")
whereFrom=substr(whereFrom,1,pathnameLength-1)
setwd(whereFrom)
up_data_pre <- read.table("up.txt", sep = "\t")
up_data <- read.table("up.txt", sep = "\t", header = T)
colnames(up_data)
<- c(as.character(up_data_pre[1, 1]), as.character(up_data_pre[1,
2]), as.character(up_data_pre[1, 3]), as.character(up_data_pre[1, 4]))
down_data_pre <- read.table("down.txt", sep = "\t")
down_data <- read.table("down.txt", sep = "\t", header = T)
colnames(down_data)
<- c(as.character(down_data_pre[1, 1]),
as.character(down_data_pre[1, 2]), as.character(down_data_pre[1, 3]),
as.character(down_data_pre[1, 4]))
xlim_up_1 <-
ceiling(max(up_data[ ,2]) / (5 * 10 ^(nchar(ceiling(max(up_data[ ,2]))) -
2))) * (5 * 10 ^(nchar(ceiling(max(up_data[ ,2]))) - 2))
xlim_up_2
<- ceiling(max(up_data[ ,3]) / (5 * 10 ^(nchar(ceiling(max(up_data[
,3]))) - 2))) * (5 * 10 ^(nchar(ceiling(max(up_data[ ,3]))) - 2))
xlim_down_1
<- ceiling(max(down_data[ ,2]) / (5 * 10
^(nchar(ceiling(max(down_data[ ,2]))) - 2))) * (5 * 10
^(nchar(ceiling(max(down_data[ ,2]))) - 2))
xlim_down_2 <-
ceiling(max(down_data[ ,3]) / (5 * 10 ^(nchar(ceiling(max(down_data[
,3]))) - 2))) * (5 * 10 ^(nchar(ceiling(max(down_data[ ,3]))) - 2))
### rect model:
# x,y 矩形左上角點的坐標苦丁; rx,ry 圓角矩形浸颓;width,height 矩形的寬和高(從左上角的點向右向下延伸); fill 填充顏色旺拉;stroke 線的顏色产上;stroke-width 線的寬度;opacity 透明度
# up_data rect
for (i in 1:nrow(up_data)) {
? up_data[i, 5] <- 2.5 * 35.43307 + 1.5 * 35.43307 + (nrow(up_data[1:i,]) - 1) * (0.15 + 0.03) * 35.43307
}
names(up_data)[5] <- "y"
up_data$x <- (1.9 + 4 + 0.25) * 35.43307
for (i in 1:nrow(up_data)) {
? up_data[i, 7] <- up_data[i, 3] * (4 * 35.43307) / xlim_up_2
}
names(up_data)[7] <- "width"
up_data$rect
= paste("
width=\"", up_data$width, ?"\" height=\"", 0.15 * 35.43307, "\"
style=\"fill:#", up_data$fill, "\"/>", sep = "")
# down_data rect
for (i in 1:nrow(down_data)) {
? down_data[i, 5] <- 2.5 * 35.43307 + 1.5 * 35.43307 + (nrow(down_data[1:i,]) - 1) * (0.15 + 0.03) * 35.43307
}
names(down_data)[5] <- "y"
for (i in 1:nrow(down_data)) {
? down_data[i, 6] <- (1.9 + 4 + 0.25 + 4 + 0.7 + 4) * 35.43307 - down_data[i, 3] * (4 * 35.43307) / xlim_down_2
}
names(down_data)[6] <- "x"
for (i in 1:nrow(down_data)) {
? down_data[i, 7] <- down_data[i, 3] * (4 * 35.43307) / xlim_down_2
}
names(down_data)[7] <- "width"
down_data$rect
= paste("
width=\"", down_data$width, ?"\" height=\"", 0.15 * 35.43307, "\"
style=\"fill:#", down_data$fill, "\"/>", sep = "")
### polyline model:
# up_data polyline
for (i in 1:nrow(up_data)) {
? up_data[i, 9] = (1.9 + 4 + 0.25) * 35.43307 + up_data[i, 2] * (4 * 35.43307) / xlim_up_1
}
names(up_data)[9] <- "x1"
for (i in 1:nrow(up_data)) {
? up_data[i, 10] = 2.5 * 35.43307 + 1.5 * 35.43307 + 0.075 * 35.43307 + (nrow(up_data[1:i,]) - 1) * (0.15 + 0.03) * 35.43307
}
names(up_data)[10] <- "y1"
polyline_1
<- paste("
up_data$y1, sep = ""), collapse = " "), "\"
style=\"fill:white;stroke:black;stroke-width:0.8;fill-opacity:0\"/>")
# down_data polyline
for (i in 1:nrow(down_data)) {
? down_data[i, 9] = (1.9 + 4 + 0.25 + 4 + 0.7 + 4) * 35.43307 - down_data[i, 2] * (4 * 35.43307) / xlim_down_1
}
names(down_data)[9] <- "x1"
for (i in 1:nrow(down_data)) {
? down_data[i, 10] = 2.5 * 35.43307 + 1.5 * 35.43307 + 0.075 * 35.43307 + (nrow(down_data[1:i,]) - 1) * (0.15 + 0.03) * 35.43307
}
names(down_data)[10] <- "y1"
polyline_2
<- paste("
down_data$y1, sep = ""), collapse = " "), "\"
style=\"fill:white;stroke:black;stroke-width:0.8;fill-opacity:0\"/>")
polyline_left_1
<- paste("
+ max(up_data$width[1], up_data[1, 2] * (4 * 35.43307) / xlim_up_1) +
1/5 * (4 * 35.43307 - max(up_data$width[1], up_data[1, 2] * (4 *
35.43307) / xlim_up_1)), up_data$y1[1], sep = ","),
? ? ? ? ? ? ? ? ? ? ? ? ?paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[1], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ? ?paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ?paste((1.9 + 4 + 0.25) * 35.43307 +
max(up_data$width[nrow(up_data)/3], up_data[nrow(up_data)/3, 2] * (4 *
35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -
max(up_data$width[nrow(up_data)/3], up_data[nrow(up_data)/3, 2] * (4 *
35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3], sep = ","),
? ? ? ? ? ? ? ? ? ? ? ? ?"\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")
polyline_left_2
<- paste("
+ max(up_data$width[nrow(up_data)/3 + 1], up_data[nrow(up_data)/3 + 1,
2] * (4 * 35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -
max(up_data$width[nrow(up_data)/3 + 1], up_data[nrow(up_data)/3 + 1, 2] *
(4 * 35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3 + 1], sep =
","),
? ? ? ? ? ? ? ? ? ? ? ? ?paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3 + 1], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ? ?paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3 * 2], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ?paste((1.9 + 4 + 0.25) * 35.43307 +
max(up_data$width[nrow(up_data)/3 * 2], up_data[nrow(up_data)/3 * 2, 2] *
(4 * 35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -
max(up_data$width[nrow(up_data)/3 * 2], up_data[nrow(up_data)/3 * 2, 2] *
(4 * 35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3 * 2], sep =
","),
? ? ? ? ? ? ? ? ? ? ? ? ?"\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")
polyline_left_3
<- paste("
+ max(up_data$width[nrow(up_data)/3 * 2 + 1], up_data[nrow(up_data)/3 *
2 + 1, 2] * (4 * 35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -
max(up_data$width[nrow(up_data)/3 * 2 + 1], up_data[nrow(up_data)/3 * 2 +
1, 2] * (4 * 35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3 * 2 +
1], sep = ","),
? ? ? ? ? ? ? ? ? ? ? ? ?paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3 * 2 + 1], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ? ?paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3 * 3], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ?paste((1.9 + 4 + 0.25) * 35.43307 +
max(up_data$width[nrow(up_data)/3 * 3], up_data[nrow(up_data)/3 * 3, 2] *
(4 * 35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -
max(up_data$width[nrow(up_data)/3 * 3], up_data[nrow(up_data)/3 * 3, 2] *
(4 * 35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3 * 3], sep =
","),
? ? ? ? ? ? ? ? ? ? ? ? ?"\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")
polyline_right_1
<- paste("
35.43307 + 4/5 * (4 * 35.43307 - max(down_data$width[1], down_data[1,
2] * (4 * 35.43307) / xlim_down_1)), down_data$y1[1], sep = ","),
? ? ? ? ? ? ? ? ? ? ? ? ? paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[1], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ? ? paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(down_data)/3], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ? paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307 +
4/5 * (4 * 35.43307 - max(down_data$width[nrow(down_data)/3],
down_data[nrow(down_data)/3, 2] * (4 * 35.43307) / xlim_down_1)),
down_data$y1[nrow(down_data)/3], sep = ","),
? ? ? ? ? ? ? ? ? ? ? ? ? "\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")
polyline_right_2
<- paste("
35.43307 + 4/5 * (4 * 35.43307 - max(down_data$width[nrow(up_data)/3 +
1], down_data[nrow(up_data)/3 + 1, 2] * (4 * 35.43307) / xlim_down_1)),
down_data$y1[nrow(up_data)/3 + 1], sep = ","),
? ? ? ? ? ? ? ? ? ? ? ? ? paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(up_data)/3 + 1], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ? ? paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(down_data)/3 * 2], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ? paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307 +
4/5 * (4 * 35.43307 - max(down_data$width[nrow(down_data)/3 * 2],
down_data[nrow(down_data)/3 * 2, 2] * (4 * 35.43307) / xlim_down_1)),
down_data$y1[nrow(down_data)/3 * 2], sep = ","),
? ? ? ? ? ? ? ? ? ? ? ? ? "\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")
polyline_right_3
<- paste("
35.43307 + 4/5 * (4 * 35.43307 - max(down_data$width[nrow(up_data)/3 * 2
+ 1], down_data[nrow(up_data)/3 * 2 + 1, 2] * (4 * 35.43307) /
xlim_down_1)), down_data$y1[nrow(up_data)/3 * 2 + 1], sep = ","),
? ? ? ? ? ? ? ? ? ? ? ? ? paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(up_data)/3 * 2 + 1], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ? ? paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(down_data)/3 * 3], sep = ","),?
? ? ? ? ? ? ? ? ? ? ? ? paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307 +
4/5 * (4 * 35.43307 - max(down_data$width[nrow(down_data)/3 * 3],
down_data[nrow(down_data)/3 * 3, 2] * (4 * 35.43307) / xlim_down_1)),
down_data$y1[nrow(down_data)/3 * 3], sep = ","),
? ? ? ? ? ? ? ? ? ? ? ? ? "\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")
### line model:
# up_data y-ticks
up_data$Y_ticks
<- paste("
x2=\"", up_data$x - 0.15 * 35.43307, "\" y2=\"", up_data$y1, "\"
style=\"stroke:black;stroke-width:0.5\"/>", sep = "")
# down_data y-ticks
down_data$Y_ticks
<- paste("
y1=\"", down_data$y1, "\" x2=\"", (17.2 + 1.9 - 4 - 0.1) * 35.43307, "\"
y2=\"", down_data$y1, "\"
style=\"stroke:black;stroke-width:0.5\"/>", sep = "")
# up_data x & -ticks_bottom
up_data_x_bottom
<- paste("
1.5 * 35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 + 0.03 *
35.43307, "\" x2=\"", 217.9134 + 4 * 35.43307, "\" y2=\"", 2.5 *
35.43307 + 1.5 * 35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 +
0.03 * 35.43307, "\" style=\"stroke:black;stroke-width:1\"/>", sep =
"")
up_data_x_ticks_bottom <- data.frame(seq(0, xlim_up_2, xlim_up_2 / 5))
up_data_x_ticks_bottom$ticks
<- paste("
up_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_up_2, "\" y1=\"", 2.5
* 35.43307 + 1.5 * 35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 +
0.03 * 35.43307, "\" x2=\"", (1.9 + 4 + 0.25) * 35.43307 +
up_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_up_2, "\" y2=\"", 2.5
* 35.43307 + 1.5 * 35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 +
0.15 * 35.43307 + 0.03 * 35.43307, "\"
style=\"stroke:black;stroke-width:0.5\"/>", sep = "")
# down_data x & -ticks_bottom
down_data_x_bottom
<- paste("
1.5 * 35.43307 + nrow(down_data) * (0.15 + 0.03) * 35.43307 + 0.03 *
35.43307, "\" x2=\"", 384.4488 + 4 * 35.43307, "\" y2=\"", 2.5 *
35.43307 + 1.5 * 35.43307 + nrow(down_data) * (0.15 + 0.03) * 35.43307 +
0.03 * 35.43307, "\" style=\"stroke:black;stroke-width:1\"/>", sep =
"")
down_data_x_ticks_bottom <- data.frame(seq(0, xlim_down_2, xlim_down_2 / 5))
down_data_x_ticks_bottom$ticks
<- paste("
down_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_down_2, "\" y1=\"",
2.5 * 35.43307 + 1.5 * 35.43307 + nrow(down_data) * (0.15 + 0.03) *
35.43307 + 0.03 * 35.43307, "\" x2=\"", (17.2 + 1.9 - 4 - 0.25) *
35.43307 - down_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_down_2,
"\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 + nrow(down_data) * (0.15 +
0.03) * 35.43307 + 0.15 * 35.43307 + 0.03 * 35.43307, "\"
style=\"stroke:black;stroke-width:0.5\"/>", sep = "")
# up_data x & -ticks_top
up_data_x_top
<- paste("
1.5 * 35.43307 - (0.03 + 0.03) * 35.43307, "\" x2=\"", 217.9134 + 4 *
35.43307, "\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) *
35.43307, "\" style=\"stroke:black;stroke-width:1\"/>", sep = "")
up_data_x_ticks_top <- data.frame(seq(0, xlim_up_1, xlim_up_1 / 5))
up_data_x_ticks_top$ticks
<- paste("
up_data_x_ticks_top[,1] * (4 * 35.43307) / xlim_up_1, "\" y1=\"", 2.5 *
35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) * 35.43307, "\" x2=\"", (1.9 +
4 + 0.25) * 35.43307 + up_data_x_ticks_top[,1] * (4 * 35.43307) /
xlim_up_1, "\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) *
35.43307 - 0.15 * 35.43307, "\"
style=\"stroke:black;stroke-width:0.5\"/>", sep = "")
# down_data x & -ticks_top
down_data_x_top
<- paste("
1.5 * 35.43307 - (0.03 + 0.03) * 35.43307, "\" x2=\"", 384.4488 + 4 *
35.43307, "\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) *
35.43307, "\" style=\"stroke:black;stroke-width:1\"/>", sep = "")
down_data_x_ticks_top <- data.frame(seq(0, xlim_down_1, xlim_down_1 / 5))
down_data_x_ticks_top$ticks
<- paste("
down_data_x_ticks_top[,1] * (4 * 35.43307) / xlim_down_1, "\" y1=\"",
2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) * 35.43307, "\" x2=\"",
(17.2 + 1.9 - 4 - 0.25) * 35.43307 - down_data_x_ticks_top[,1] * (4 *
35.43307) / xlim_down_1, "\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 -
(0.03 + 0.03) * 35.43307 - 0.15 * 35.43307, "\"
style=\"stroke:black;stroke-width:0.5\"/>", sep = "")
### text model
up_data_x_ticks_bottom$text
<- paste("
up_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_up_2 -
nchar(up_data_x_ticks_bottom[,1]) * 2, "\" y=\"", 2.5 * 35.43307 + 1.5 *
35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 + 0.03 * 35.43307 +
0.5 * 35.43307, "\" font-family=\"Arial\" font-size=\"8\"
fill=\"black\" >", up_data_x_ticks_bottom[,1], "", sep =
"")
down_data_x_ticks_bottom$text <- paste("
(17.2 + 1.9 - 4 - 0.25) * 35.43307 - down_data_x_ticks_bottom[,1] * (4 *
35.43307) / xlim_down_2 - nchar(down_data_x_ticks_bottom[,1]) * 2, "\"
y=\"", 2.5 * 35.43307 + 1.5 * 35.43307 + nrow(down_data) * (0.15 + 0.03)
* 35.43307 + 0.03 * 35.43307 + 0.5 * 35.43307, "\"
font-family=\"Arial\" font-size=\"8\" fill=\"black\" >",
down_data_x_ticks_bottom[,1], "", sep = "")
up_data_x_ticks_top$text
<- paste("
up_data_x_ticks_top[,1] * (4 * 35.43307) / xlim_up_1 -
nchar(up_data_x_ticks_top[,1]) * 2, "\" y=\"", 2.5 * 35.43307 + 1.5 *
35.43307 - (0.03 + 0.03) * 35.43307 - 0.25 * 35.43307, "\"
font-family=\"Arial\" font-size=\"8\" fill=\"black\" >",
up_data_x_ticks_top[,1], "", sep = "")
down_data_x_ticks_top$text
<- paste("
down_data_x_ticks_top[,1] * (4 * 35.43307) / xlim_down_1 -
nchar(down_data_x_ticks_top[,1]) * 2, "\" y=\"", 2.5 * 35.43307 + 1.5 *
35.43307 - (0.03 + 0.03) * 35.43307 - 0.25 * 35.43307, "\"
font-family=\"Arial\" font-size=\"8\" fill=\"black\" >",
down_data_x_ticks_top[,1], "", sep = "")
up_data$text
<- paste("
up_data$y1 + 0.075 * 35.43307, "\" text-anchor=\"end\"
font-family=\"Arial\" font-size=\"6\" fill=\"black\" >", up_data[
,1], "", sep = "")
down_data$text <-
paste("
down_data$y1 + 0.075 * 35.43307, "\" font-family=\"Arial\"
font-size=\"6\" fill=\"black\" >", down_data[ ,1], "",
sep = "")
labels <- data.frame(paste("
0.25 + 4) * 35.43307, "\" y=\"", 2.5 * 35.43307 + 1.5 * 35.43307 +
nrow(up_data) * (0.15 + 0.03) * 35.43307 + 0.03 * 35.43307 + 1 *
35.43307, "\" text-anchor=\"end\" font-family=\"Arial\" font-size=\"8\"
fill=\"black\" >", colnames(up_data)[3], "", sep = ""),
? ? ? ? ? ? ? ? ? ?paste("
35.43307, "\" y=\"", 2.5 * 35.43307 + 1.5 * 35.43307 + nrow(up_data) *
(0.15 + 0.03) * 35.43307 + 0.03 * 35.43307 + 1 * 35.43307, "\"
font-family=\"Arial\" font-size=\"8\" fill=\"black\" >",
colnames(down_data)[3], "", sep = ""),
? ? ?paste("
2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) * 35.43307 - 0.25 *
35.43307 - 0.5 * 35.43307, "\" text-anchor=\"end\" font-family=\"Arial\"
font-size=\"8\" fill=\"black\" >", colnames(up_data)[2],
"", sep = ""),
? ? ? ? ? ? ? ? ? ? ?paste("
x=\"", (1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, "\" y=\"", 2.5 * 35.43307 +
1.5 * 35.43307 - (0.03 + 0.03) * 35.43307 - 0.25 * 35.43307 - 0.5 *
35.43307, "\" font-family=\"Arial\" font-size=\"8\" fill=\"black\"
>", colnames(down_data)[2], "", sep = "")
)
BP
<- paste("
"\" y=\"", (up_data$y1[nrow(up_data)/3] - up_data$y1[1])/2 +
up_data$y1[1] + 0.075 * 35.43307, "\" text-anchor=\"middle\"
font-family=\"Arial\" font-size=\"8\" fill=\"black\"
>BP", sep = "")
CC <- paste("
(1.9 + 4 + 0.25 + 4 + 0.35) * 35.43307, "\" y=\"",
(up_data$y1[nrow(up_data)/3 * 2] - up_data$y1[nrow(up_data)/3])/2 +
up_data$y1[nrow(up_data)/3] + 0.075 * 35.43307, "\"
text-anchor=\"middle\" font-family=\"Arial\" font-size=\"8\"
fill=\"black\" >CC", sep = "")
MF <-
paste("
y=\"", (up_data$y1[nrow(up_data)/3 * 3] - up_data$y1[nrow(up_data)/3 *
2])/2 + up_data$y1[nrow(up_data)/3 * 2] + 0.075 * 35.43307, "\"
text-anchor=\"middle\" font-family=\"Arial\" font-size=\"8\"
fill=\"black\" >MF", sep = "")
# write .svg file
first_line <- data.frame("",
? ? ? ? ? ? ? ? ? ? ? ? ?"
? ? ? ? ? ? ? ? ? ? ? ? ?"\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">",
? ? ? ? ? ? ? ? ? ? ? ? ?"",
? ? ? ? ? ? ? ? ? ? ? ? ?paste("", "\t")
)
write.table(first_line[1, 1], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE)
write.table(first_line[1, 2], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(first_line[1, 3], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(first_line[1, 4], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(first_line[1, 5], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(up_data$rect, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(down_data$rect, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(polyline_1, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(polyline_2, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(polyline_left_1, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(polyline_left_2, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(polyline_left_3, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(polyline_right_1, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(polyline_right_2, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(polyline_right_3, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(up_data$Y_ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(down_data$Y_ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(up_data_x_bottom, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(up_data_x_ticks_bottom$ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(down_data_x_bottom, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(down_data_x_ticks_bottom$ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(up_data_x_top, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(up_data_x_ticks_top$ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(down_data_x_top, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(down_data_x_ticks_top$ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(up_data_x_ticks_bottom$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(down_data_x_ticks_bottom$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(up_data_x_ticks_top$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(down_data_x_ticks_top$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(up_data$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(down_data$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(labels, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(BP, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(CC, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
write.table(MF, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
last_line <- data.frame(paste(""))
write.table(last_line[1, 1], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)
腳本比較長蛾狗,不過你們完全不需要看晋涣,只要復(fù)制粘貼一下就OK啦??
P.S. 想看懂代碼的可以先學(xué)一學(xué)基礎(chǔ)的R處理數(shù)據(jù)和SVG腳本(http://tutorials.jenkov.com/svg/index.html)。另外沉桌,百度云里面我放了R腳本和示例文件哦(鏈接: https://pan.baidu.com/s/1geLSbpL 密碼: b7wn)谢鹊。目前我測試了幾次數(shù)據(jù),只要配置文件沒問題應(yīng)該就沒問題了蒲牧,后期有問題的可以發(fā)我郵箱(haozd1992@163.com)撇贺,歡迎提問,共同進步冰抢!