Skip to content

Instantly share code, notes, and snippets.

@ranjiGT
Created May 2, 2021 09:54
Show Gist options
  • Save ranjiGT/6f880faf62dd77c94a49c278621de88d to your computer and use it in GitHub Desktop.
Save ranjiGT/6f880faf62dd77c94a49c278621de88d to your computer and use it in GitHub Desktop.
A touch up script in R for problem-solving
library(tidyverse)
category <- c("red", "blue", "green", "yellow")
tag <- c("yes", "no", "maybe", "idk")
value <- c(21, 1, 10, 9)
df <- data.frame(category, tag, value) %>%
mutate(prop = value/sum(value))
df %>%
ggplot(aes(tag, prop, fill = category))+
geom_col()+
geom_text(aes(label = prop %>% scales::percent()), position=position_dodge(width=0.9), vjust=-0.25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment