Skip to content

Instantly share code, notes, and snippets.

@steveharoz
Created October 28, 2021 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveharoz/eef07bb1de239365133b7f27dd9a0e9d to your computer and use it in GitHub Desktop.
Save steveharoz/eef07bb1de239365133b7f27dd9a0e9d to your computer and use it in GitHub Desktop.
Pie chart with subcategories
library(tidyverse)
set.seed(999)
data = tibble(
name = c("A1", "A2", "A3", "A4", "B1", "B2", "B3", "B4", "C1", "C2"),
value = rnorm(10, 10, sd = 3),
color = c(
hcl(220, seq(60, 30, -10), seq(50, 80, 10)),
hcl(0, seq(60, 30, -10), seq(50, 80, 10)),
hcl(120, seq(60, 50, -10), seq(50, 60, 10))
)
)
ggplot(data) +
aes(x="", y=value, fill=fct_inorder(factor(color))) +
geom_col(width = 1) +
scale_fill_identity() +
coord_polar("y", start=0) +
theme_void(18) + theme(title = element_text(hjust=1)) +
labs(title = "Who has the majority: blues vs. greens+reds?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment