(轉(zhuǎn)帖)-GO enrichment (Easier)

原文地址: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)撇贺,歡迎提問,共同進步冰抢!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末松嘶,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子挎扰,更是在濱河造成了極大的恐慌翠订,老刑警劉巖巢音,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異尽超,居然都是意外死亡官撼,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進店門似谁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來傲绣,“玉大人,你說我怎么就攤上這事巩踏⊥核校” “怎么了?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵塞琼,是天一觀的道長菠净。 經(jīng)常有香客問我,道長彪杉,這世上最難降的妖魔是什么毅往? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮派近,結(jié)果婚禮上攀唯,老公的妹妹穿的比我還像新娘。我一直安慰自己构哺,他們只是感情好革答,可當(dāng)我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布战坤。 她就那樣靜靜地躺著曙强,像睡著了一般。 火紅的嫁衣襯著肌膚如雪途茫。 梳的紋絲不亂的頭發(fā)上碟嘴,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天,我揣著相機與錄音囊卜,去河邊找鬼娜扇。 笑死,一個胖子當(dāng)著我的面吹牛栅组,可吹牛的內(nèi)容都是我干的雀瓢。 我是一名探鬼主播,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼玉掸,長吁一口氣:“原來是場噩夢啊……” “哼刃麸!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起司浪,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤泊业,失蹤者是張志新(化名)和其女友劉穎把沼,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體吁伺,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡饮睬,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了篮奄。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片捆愁。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖窟却,靈堂內(nèi)的尸體忽然破棺而出牙瓢,到底是詐尸還是另有隱情,我是刑警寧澤间校,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布矾克,位于F島的核電站,受9級特大地震影響憔足,放射性物質(zhì)發(fā)生泄漏胁附。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一滓彰、第九天 我趴在偏房一處隱蔽的房頂上張望控妻。 院中可真熱鬧,春花似錦揭绑、人聲如沸弓候。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽菇存。三九已至,卻和暖如春邦蜜,著一層夾襖步出監(jiān)牢的瞬間依鸥,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工悼沈, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留贱迟,地道東北人。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓絮供,卻偏偏與公主長得像衣吠,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子壤靶,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容