2017-10-16 205 views
0

我試圖用GOplot包,特別是GOHeat()函數繪製我的Gene Ontology數據。不幸的是,顯示基因名稱時存在問題 - 圖上的x軸標籤。這裏有一個問題,可視化:GOHeat -x軸標籤(基因名稱)不會顯示在圖上

從小品的情節就是它看起來應該像: enter image description here

,這裏是它的外觀就像當我繪製它:

enter image description here

我決定去仔細看看GOHeat()函數,它的優點很簡單,整個函數是here但是我試圖修改ggplot():

g <- ggplot() + 
    geom_tile(data = df_o, aes(x = x, y = y, fill = z))+ 
    scale_x_discrete(breaks = 1:length(unique(df_o$x)), labels = unique(df_o$lab)) + 
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5), axis.title.x=element_blank(), axis.title.y=element_blank(), 
      axis.text.y = element_text(size = 14), panel.background=element_blank(), panel.grid.major=element_blank(), 
      panel.grid.minor=element_blank()) 

我認爲,在axis.text.x = element_text(...) marigins,但我的努力並沒有改變陰謀,甚至出現ome錯誤。

爲了方便起見我顯示的數據看起來的樣子:

> head(unique(df_o$x)) 
[1] 1 2 3 4 5 6 
> head(unique(df_o$lab)) 
[1] TGFBR3 NRP2 GNA13 SLC22A5 APOE LEPR 
37 Levels: ACVRL1 AMOT APOE ATP6V0A1 CAV1 CDH2 CDH5 CERKL CXCR4 ECSCR  EFNB2 FGF2 ... VANGL2 

我會爲任何線索如何「打開」 X軸標籤非常感謝。

回答

1

這裏是一個固定功能:

GOHeat_fix <- function (data, nlfc, fill.col) 
{ 
    x <- y <- z <- NULL 
    if (missing(nlfc)) 
    nlfc <- 0 
    else nlfc <- nlfc 
    if (missing(fill.col)) 
    fill.col <- c("firebrick", "white", "dodgerblue") 
    else fill.col <- fill.col 
    distance <- dist(data) 
    cluster <- hclust(distance) 
    M <- dim(data)[2] 
    nterm <- M - nlfc 
    if (nlfc == 0) { 
    s <- rowSums(data[, 1:nterm]) 
    tmp <- NULL 
    for (r in 1:nrow(data)) { 
     tmp <- c(tmp, as.numeric(gsub(1, s[r], data[r, 1:nterm]))) 
    } 
    } 
    else { 
    tmp <- NULL 
    for (r in 1:nrow(data)) { 
     tmp <- c(tmp, as.numeric(gsub(1, data[r, (nterm + 
                1)], data[r, 1:nterm]))) 
    } 
    } 
    df <- data.frame(x = factor(rep(cluster$order, each = nterm)), y = rep(colnames(data[, 
                       1:nterm]), length(rownames(data))), z = tmp, lab = rep(rownames(data), 
                                     each = nterm)) 
    df_o <- df[order(df$x), ] 
    g <- ggplot() + 
    geom_tile(data = df_o, aes(x = x, y = y, fill = z)) + 
    scale_x_discrete(breaks = 1:length(unique(df_o$x)), labels = unique(df_o$lab)) + 
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1), 
      axis.title.x = element_blank(), 
      axis.title.y = element_blank(), 
      axis.text.y = element_text(size = 14), 
      panel.background = element_blank(), 
      panel.grid.major = element_blank(), 
      panel.grid.minor = element_blank()) + 
    coord_fixed() 
    if (nlfc == 0) { 
    g + scale_fill_gradient2("Count", space = "Lab", low = fill.col[2], 
          mid = fill.col[3], high = fill.col[1]) 
    } 
    else { 
    g + scale_fill_gradient2("logFC", space = "Lab", low = fill.col[3], 
          mid = fill.col[2], high = fill.col[1]) 
    } 
} 

例如:

library(GOplot) 
data(EC) 
circ <- circle_dat(EC$david, EC$genelist) 
chord <- chord_dat(data = circ, genes = EC$genes, process = EC$process) 
GOHeat_fix(chord[,-8], nlfc = 0) 

enter image description here

我帶標籤的解決了這一問題,並添加coord_fixed()因爲這是熱圖是怎樣通常由。

+0

哇,太棒了,非常感謝你! – Adamm