Skip to content

Instantly share code, notes, and snippets.

@loukesio
Last active August 3, 2023 13:53
Show Gist options
  • Select an option

  • Save loukesio/5a9c53d10fbbeaf33a8f00ee7921bc43 to your computer and use it in GitHub Desktop.

Select an option

Save loukesio/5a9c53d10fbbeaf33a8f00ee7921bc43 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
tibble(species=c(rep("tiger",2),rep("elephant",2)),
type=rep(c("upregulated","downregulated"),2),
counts=c(121,117,219,234)) %>%
ggplot() +
geom_col(aes(species,counts,fill=type), position = position_dodge()) +
scale_fill_manual(values=c("#ffa345","#624185")) +
geom_text(aes(x=species, y=counts+5, label=counts, group=type), position = position_dodge(width = 0.9)) + # Here, do not forget to GROUP!
labs(title="Group the geom_text to be able to dodge it!") +
theme_bw() +
theme(text=element_text(size=15),
title=element_text(hjust = 0.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment