Created
October 28, 2021 10:36
-
-
Save steveharoz/eef07bb1de239365133b7f27dd9a0e9d to your computer and use it in GitHub Desktop.
Pie chart with subcategories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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