2017-03-23 14 views
-3

enter image description hereR 스택 바 플롯 사용 ggplot 2

은 업로드 된 사진과 같은 % 스택 플롯을 확인합니다. 이 내 스크립트 내가 다음과 같은 오류 얻을 : 다시

Goterm up down 
metal ion transmembrane transporter activity 10 90 
translational elongation 22.22222222 77.77777778 
metal ion transport 25 75 
translation 30.08474576 69.91525424 
aminoacyl-tRNA ligase activity 30.76923077 69.23076923 
anchored component of membrane 33.33333333 66.66666667 
apoptotic process 33.33333333 66.66666667 
ribosome 34.11764706 65.88235294 
regulation of cell cycle 35 65 
translation elongation factor activity 35.71428571 64.28571429 
cell wall 37.20930233 62.79069767 
obsolete microsome 37.5 62.5 
biosynthetic process 38.46153846 61.53846154 
extracellular region 38.88888889 61.11111111 
unfolded protein binding 42.10526316 57.89473684 
protein folding 43.66197183 56.33802817 
glutamine metabolic process 43.75 56.25 
cellular amino acid metabolic process 46.875 53.125 
fungal-type vacuole 48.61111111 51.38888889 
glycolytic process 53.33333333 46.66666667 
oxidoreductase activity 54.03225806 45.96774194 
oxidation-reduction process 54.57875458 45.42124542 
plasma membrane 55.6097561 44.3902439 
regulation of cell size 57.14285714 42.85714286 
cytosol 57.25806452 42.74193548 
transmembrane transport 57.48792271 42.51207729 
flavin adenine dinucleotide binding 62.16216216 37.83783784 
metalloendopeptidase activity 63.15789474 36.84210526 
transmembrane transporter activity 65.71428571 34.28571429 
structural constituent of ribosome 66.34146341 33.65853659 
chronological cell aging 66.66666667 33.33333333 
transporter activity 69.33333333 30.66666667 
mitochondrial inner membrane 72 28 
substrate-specific transmembrane transporter activity 75 25 
mitochondrial outer membrane 76.11940299 23.88059701 
integral component of mitochondrial inner membrane 92.85714286 7.142857143 
fungal-type cell wall 100 0 

모든 피드 : GO 약관 여기

setwd("C:/Users/gmbz/Desktop/RNA analysis/Rscripts/Bar plot") #set up working directory 
res <- read.delim("GOBarPlot.txt", header=TRUE) 
head(res) 
tail(res) 
show(res) 
library(ggplot2) 
ggplot(data=res, aes(x=up, y=down, fill=GO.term)) + geom_bar() 

에 대한

gplot(data=res, aes(x=GO.term, y=up)) + geom_bar() 
**Error: stat_count() must not be used with a y aesthetic.** 

# 바 플롯을 내 데이터가?

질문 2. GOterms의 글꼴을 Times New Roman으로 어떻게 변경합니까? 그게 가능하니?

답변

2

우리가 먼저하게 할 데이터의 구조를 변경해야 그것을 사용할 수 : 라이브러리 (tidyr) 라이브러리 (dplyr)

df %>% 
    arrange(desc(up)) %>% 
    gather(direction, value, -Goterm) -> df2 
우리는 당신이 관심있는 어떤 플롯 할 수 있습니다

:

library(ggplot2) 
library(scales) 
df %>% 
    arrange(desc(up)) %>% 
    gather(direction, value, -Goterm) -> df2 
ggplot(df2) + 
    geom_col(aes(x = Goterm, y = value, fill = direction), 
      position = 'fill', 
      width = .3) + 
    scale_fill_manual(values = c('navy','red')) + 
    scale_x_discrete(limits = df$Goterm) + 
    scale_y_continuous(labels = percent_format(), expand = c(0,0)) + 
    coord_flip() + 
    theme(legend.position = 'bottom', 
      legend.direction = 'horizontal', 
      legend.title = element_blank(), 
      legend.text = element_text(size = 10), 
      legend.key.size = unit(.5, 'lines'), 
      panel.background = element_rect(fill = 'transparent'), 
      panel.grid.major.x = element_line(size = .1, 
              color = 'black', 
              linetype = 'dashed'), 
      axis.title.y = element_blank(), 
      axis.title.x = element_blank(), 
     ) 

원본 데이터 :

df <- read.table(text = ' Goterm up down 
    "metal ion transmembrane transporter activity" 10 90 
       "translational elongation" 22.22222222 77.77777778 
       "metal ion transport" 25 75 
       "translation" 30.08474576 69.91525424 
       "aminoacyl-tRNA ligase activity" 30.76923077 69.23076923 
       "anchored component of membrane" 33.33333333 66.66666667 
       "apoptotic process" 33.33333333 66.66666667 
       "ribosome" 34.11764706 65.88235294 
       "regulation of cell cycle" 35 65 
       "translation elongation factor activity" 35.71428571 64.28571429 
       "cell wall" 37.20930233 62.79069767 
       "obsolete microsome" 37.5 62.5 
       "biosynthetic process" 38.46153846 61.53846154 
       "extracellular region" 38.88888889 61.11111111 
       "unfolded protein binding" 42.10526316 57.89473684 
       "protein folding" 43.66197183 56.33802817 
       "glutamine metabolic process" 43.75 56.25 
       "cellular amino acid metabolic process" 46.875 53.125 
       "fungal-type vacuole" 48.61111111 51.38888889 
       "glycolytic process" 53.33333333 46.66666667 
       "oxidoreductase activity" 54.03225806 45.96774194 
       "oxidation-reduction process" 54.57875458 45.42124542 
       "plasma membrane" 55.6097561 44.3902439 
       "regulation of cell size" 57.14285714 42.85714286 
       "cytosol" 57.25806452 42.74193548 
       "transmembrane transport" 57.48792271 42.51207729 
       "flavin adenine dinucleotide binding" 62.16216216 37.83783784 
       "metalloendopeptidase activity" 63.15789474 36.84210526 
       "transmembrane transporter activity" 65.71428571 34.28571429 
       "structural constituent of ribosome" 66.34146341 33.65853659 
       "chronological cell aging" 66.66666667 33.33333333 
       "transporter activity" 69.33333333 30.66666667 
       "mitochondrial inner membrane" 72 28 
       "substrate-specific transmembrane transporter activity" 75 25 
       "mitochondrial outer membrane" 76.11940299 23.88059701 
       "integral component of mitochondrial inner membrane" 92.85714286 7.142857143 
       "fungal-type cell wall" 100 0', header = T, stringsAsFactors = F) 
+0

안녕하세요 GGamba, Amazing !!! 고마워. 그것은 완벽하게 작동했습니다 – George

+0

이제 또 다른 질문이 있습니다. 그래서, RNAseq 실험에서 더 큰 데이터 세트를 얻었습니다. 나는 R. Cheers에서 읽을 수 있도록 Excel 테이블에서 GOterms를 변환하는 방법을 궁금합니다! – George