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