Skip to content

Instantly share code, notes, and snippets.

@jwinternheimer
Last active August 29, 2015 14:22
Show Gist options
  • Save jwinternheimer/13907ca5d6bb6a45f95a to your computer and use it in GitHub Desktop.
Save jwinternheimer/13907ca5d6bb6a45f95a to your computer and use it in GitHub Desktop.
diversity-app
library("XML")
library("ggplot2")
library("downloader")
library('scales')
library('grid')
library('RColorBrewer')
function(input, output) {
team_url <- 'https://docs.google.com/spreadsheets/u/1/d/1E9WwcIEYuGxR8GUrmxL1iaozOk_0FKSPPWbnCDn_C0A/pubhtml'
applicants_url <- "https://docs.google.com/spreadsheets/d/11GXSEkgDnLIBWmqYWJA1VbG9xmsPPl2MFRWxvFiWmwQ/pubhtml"
urls <- list(team = team_url, applicants = applicants_url)
applicants_data <- readGoogleSheet(applicants_url, 'applicants')
applicants_data <- cleanUpData(applicants_data)
team_data <- readGoogleSheet(team_url, 'team')
team_data <- cleanUpData(team_data)
## RETURN REQUESTED DATASET
datasetInput <- reactive({
switch(input$dataset,
"The Buffer Team" = team_data,
"Applicants" = applicants_data)
})
#plots
output$genderPlot <- renderPlot({
data <- datasetInput()
department_and_gender <- data %>%
group_by(department,gender) %>%
summarise(n=n()) %>%
mutate(percent=n/sum(n),department_size=sum(n))
ggplot(department_and_gender, aes(x=reorder(department,-department_size), y=n, fill=gender)) +
geom_bar(stat="identity") + scale_fill_brewer(palette="Pastel1") +
labs(x="Area",y="Number of People", title="Gender Breakdown Across Areas")
})
output$genderTimeSeries <- renderPlot({
data <- datasetInput()
time_and_gender <- data %>%
group_by(posixDate,gender) %>%
summarise(n=n())
ggplot(time_and_gender, aes(x=posixDate, y=n, fill=gender)) +
geom_bar(stat="identity") +
scale_color_brewer(palette="Pastel1") +
labs(x="Date",y="People", title="Gender of Applicants") +
theme_minimal()
})
output$ethnicityTimeSeries <- renderPlot({
data <- datasetInput()
data <- data[-1,]
data$posixDateTime <- as.POSIXct(data$date,format="%m/%d/%Y %H:%M:%S")
data$posixDate <- as.Date(data$posixDateTime)
time_and_ethnicity <- data %>%
group_by(posixDate,ethnicity) %>%
summarise(n=n())
ggplot(time_and_ethnicity, aes(x=posixDate, y=n, fill=ethnicity)) +
geom_bar(stat="identity") +
scale_fill_brewer(palette="Pastel1") +
labs(x="Date",y="People", title="Ethnicity of Applicants") +
theme_minimal()
})
output$ethnicityPlot <- renderPlot({
data <- datasetInput()
department_and_ethnicity <- data %>%
group_by(department,ethnicity) %>%
summarise(n=n()) %>%
mutate(percent=n/sum(n),department_size=sum(n))
ggplot(department_and_ethnicity, aes(x=reorder(department,department_size), y=n, fill=ethnicity)) +
geom_bar(stat="identity") + coord_flip() +
labs(x="Area",y="People", title="Ethnicity Breakdown Across Areas") +
scale_fill_brewer(palette="Pastel1")
})
output$ethnicityPies <- renderPlot({
data <- datasetInput()
by_ethnicity <- data %>%
group_by(department,ethnicity) %>%
summarise(n=n()) %>%
mutate(percent=n/sum(n))
total_ethnicity_row <- data %>%
group_by(ethnicity) %>%
summarise(n=n()) %>%
mutate(percent=n/sum(n),department="Total")
total_ethnicity_breakdown <- rbind(by_ethnicity,total_ethnicity_row)
ggplot(total_ethnicity_breakdown,aes(x=factor(1),y=percent,fill=ethnicity)) +
geom_bar(stat="identity",width=1) +
facet_wrap(~department) +
coord_polar(theta="y") +
scale_fill_brewer(palette="Pastel1") +
theme_minimal() +
theme(axis.ticks = element_blank(), axis.text.y = element_blank(), axis.text.x = element_blank()) +
labs(x="",y="",title="Ethnicity Breakdown Across Areas")
})
output$genderPies <- renderPlot({
data <- datasetInput()
department_and_gender <- data %>%
group_by(department,gender) %>%
summarise(n=n()) %>%
mutate(percent=n/sum(n))
total_row <- data %>%
group_by(gender) %>%
summarise(n=n()) %>%
mutate(percent=n/sum(n),department="Total")
total_gender_breakdown <- rbind(department_and_gender,total_row)
total_gender_breakdown$gender <- factor(total_gender_breakdown$gender,levels=rev(levels(total_gender_breakdown$gender)))
ggplot(total_gender_breakdown,aes(x=factor(1),y=percent,fill=gender)) +
geom_bar(stat="identity",width=1) +
facet_wrap(~department) +
coord_polar(theta="y") +
scale_fill_brewer(palette="Pastel1") +
theme_minimal() +
theme(axis.ticks = element_blank(), axis.text.y = element_blank(), axis.text.x = element_blank()) +
labs(x="",y="",title="Gender Breakdown Across Areas :)")
})
#raw data
output$teamTable <- renderTable(team_data)
output$applicantsTable <- renderTable(applicants_data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment