Last active
November 6, 2019 04:37
-
-
Save danhammer/13289b89f54fe6807ecb008204c4b301 to your computer and use it in GitHub Desktop.
pie chart exploration
This file contains hidden or 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
# pie chart exploration | |
library(ggplot2) | |
library(ngram) | |
library(jsonlite) | |
library(tidyr) | |
library(RColorBrewer) | |
library(dplyr) | |
library(scales) | |
film_indicator <- "MATRIX" | |
metadata_location <- paste0("../../clean-scripts/r-data/", film_indicator, "_META.Rda") | |
load(metadata_location) | |
# Print the summary statistics for gender and race breakdown | |
summary.gender <- meta %>% | |
group_by(gender) %>% | |
summarize(lines = sum(lines), words = sum(words)) | |
summary.gender$line_summary <- summary.gender$lines/sum(meta$lines) | |
summary.gender$word_summary <- summary.gender$words/sum(meta$words) | |
print(summary.gender) | |
blank_theme <- theme_minimal()+ | |
theme( | |
axis.title.x = element_blank(), | |
axis.title.y = element_blank(), | |
panel.border = element_blank(), | |
panel.grid=element_blank(), | |
axis.ticks = element_blank(), | |
axis.text.x=element_blank(), | |
plot.title=element_text(size=14, face="bold") | |
) | |
ggplot(summary.gender, aes(x="", y=line_summary, fill=gender)) + | |
geom_bar(width = 1, stat = "identity") + | |
coord_polar("y", start=0) + | |
blank_theme + | |
annotate( | |
"text", | |
x = 1.7, | |
y = c(0.005, 0.4, 0.9), | |
label = percent(summary.gender$line_summary, 1) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@danhammer was able to recreate based on snippets you to provided also used some customization of colours and legend label using below snippets. Any advice on how to move up the 23% so it is easier to identify that it belongs to the blue (obivious, but want to make it easy on the eye), and how to capitalise the Female/Male under Gender? Thanks a lot