2017-03-23 4 views
-3

enter image description hereR Stacked Bars Grundstück mit ggplot 2

Ich mag würde% gestapelt Grundstück wie das Bild hochgeladen machen. Das ist mein Skript ist und ich erhalte die folgende Fehlermeldung:

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

# Bar Grundstück für Begriffe 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() 

Hier ist meine Daten:

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 

Jede Rückmeldung?

Frage Nr. 2. Wie kann ich die Schriftart der GOterms ändern, vorzugsweise in Times New Roman? ist das möglich?

Antwort

2

Wir müssen zunächst die Struktur der Sie Daten ändern, um es nutzbar: Bibliothek (tidyr) Bibliothek (dplyr)

df %>% 
    arrange(desc(up)) %>% 
    gather(direction, value, -Goterm) -> df2 

Wir können dann zeichnen, was Sie interessiert sind in:

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(), 
     ) 

Originaldaten:

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

Hey GGamba, erstaunlich !!! Danke vielmals. Es hat perfekt funktioniert – George

+0

Jetzt habe ich eine andere Frage. Also habe ich einen größeren Datensatz von meinen RNAseq-Experimenten. Ich frage mich, wie man die GOterms aus der Excel-Tabelle konvertiert, um sie in R. lesbar zu machen. – George