Home > Blockchain >  I need to add gene number and fold change in the same horizontal bar graph
I need to add gene number and fold change in the same horizontal bar graph

Time:11-15

I need to add Gene number and fold change in the same horizontal bar graph. The below is the data

Name Genes Enrichment fold chaneg
cellular process 10 2
Biological phase 5 5
cell process 8 9

The graph should like this below

enter image description here

CodePudding user response:

One potential option:

library(tidyverse)

df <- read.table(text = "Name   Gene    'Enrichment fold change'
'cellular process'  10  2
'Biological phase'  5   5
'cell process'  8   9", header = TRUE)

df %>%
  pivot_longer(-Name) %>%
  mutate(value = ifelse(name == "Gene", -value, value)) %>%
  ggplot(aes(x = Name, y = value, fill = name))  
  geom_col(position = position_stack())  
  coord_flip(clip = "on")  
  scale_y_continuous(labels = abs,
                     name = "          Gene Count          Enrichment FC")  
  theme(legend.position = "none")

Created on 2022-11-14 by the reprex package (v2.0.1)

  • Related