Created
April 5, 2022 02:16
-
-
Save steveharoz/d15a02edec68747d9645d97ff05488fa to your computer and use it in GitHub Desktop.
hierarchical pie
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) | |
COUNT = 40 | |
data = tibble( | |
car = paste0(sample(LETTERS, COUNT, TRUE), sample(letters, COUNT, TRUE), sample(letters, COUNT, TRUE)), | |
value = rnorm(COUNT, 3), | |
group = c(rep("Petrol", COUNT/2), rep("Hybrid", COUNT/4), rep("Pure Electric", COUNT/8), rep("Diesel", COUNT/8)) | |
) | |
data = data %>% | |
arrange(group, value) %>% | |
mutate(isOdd = rep(c(T,F), COUNT/2)) %>% | |
mutate(y_start = c(0, lag(cumsum(value))[-1])) | |
ggplot(data) + | |
aes(ymin=y_start, ymax=y_start+value, fill=group, color=group, alpha = isOdd) + | |
geom_rect(alpha=1, xmin=0, xmax=1) + | |
geom_rect(color=NA, fill="white", xmin=.7, xmax=1) + | |
geom_text(aes(label=car, y=y_start+value/2), x=.8, color="white", alpha=.75) + | |
scale_alpha_manual(values = c(0, 0.25)) + | |
scale_color_manual(values = c("#183263", "#244D8B", "#008001", "black")) + | |
scale_fill_manual(values = c("#183263", "#244D8B", "#008001", "black")) + | |
coord_polar("y", start=0) + | |
theme_void() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment