Skip to content

Commit

Permalink
Added Education Level Distribution + logo change
Browse files Browse the repository at this point in the history
  • Loading branch information
lboullu committed Apr 16, 2020
1 parent 1600126 commit 03e6c99
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
42 changes: 38 additions & 4 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ server <- function(input, output, session) {
summarise(nb_surveyed=n()) %>%
ungroup() %>%
group_by(Country) %>%
mutate(perc_surveyed_by_country = (nb_surveyed / sum(nb_surveyed)) * 100) %>%
mutate(perc_surveyed_by_country = (nb_surveyed / sum(nb_surveyed))) %>%
ungroup() %>%
mutate(country_gender_text = paste0(
"Country: ", Country, "\n",
"Gender: ", Dem_gender, "\n",
"# of surveyed: ", nb_surveyed, "\n",
"% of surveyed: ", round(perc_surveyed_by_country, 2), "\n"))
"% of surveyed: ", round(perc_surveyed_by_country*100, 2), "%\n"))
processed_data$Country <- factor(processed_data$Country, levels = rev(country_list))
processed_data$Dem_gender <- factor(processed_data$Dem_gender, levels = rev(genders))
pGender100 <- ggplot(data = processed_data) +
geom_bar(aes(x = Country, y = perc_surveyed_by_country, fill = Dem_gender, text = country_gender_text), stat="identity") +
geom_bar(aes(x = Country, y = perc_surveyed_by_country, fill = Dem_gender, text = country_gender_text), stat="identity", size=0.5, color="grey20") +
scale_fill_manual(name="Gender", values=c("Female" = "#00c7b8ff", "Male" = "#31233bff","Other/would rather not say" = "#fbedcdff")) +
coord_flip() +
scale_y_continuous(breaks=seq(0,1,0.1),labels = scales::percent_format(accuracy = 1),expand=c(0,0))+
scale_x_discrete(expand=c(0,0))+
labs(x = "Country", y = "% Gender") +
theme_classic()
theme_classic() +
theme(legend.position="top")

#Generating Age Pyramid (by @ggautreau) ----

Expand All @@ -73,11 +76,42 @@ server <- function(input, output, session) {
labs(x = "Age ranges", y = "# of surveyed") +
theme_classic()

#Generating Education Distribution Plot (by @ggautreau) ----

education <- c("- PhD/Doctorate", "- College degree, bachelor, master", "- Some College, short continuing education or equivalent", "- Up to 12 years of school ", "- Up to 9 years of school", "- Up to 6 years of school", "- None")

processed_data = data %>%
filter(Country%in%country_list,Dem_edu %in% education) %>%
group_by(Country,Dem_edu) %>%
summarise(nb_surveyed=n()) %>%
ungroup() %>%
group_by(Dem_edu) %>%
mutate(perc_surveyed_by_country = (nb_surveyed / sum(nb_surveyed))) %>%
ungroup() %>%
mutate(country_edu_text = paste0(
"Country: ", Country, "\n",
"Education: ", Dem_edu, "\n",
"# of surveyed: ", nb_surveyed, "\n",
"% of surveyed: ", round(perc_surveyed_by_country*100, 2), "%\n"))
processed_data$Country <- factor(processed_data$Country, levels = rev(country_list))
processed_data$Dem_edu <- factor(processed_data$Dem_edu, levels = rev(education))

pEdu <- ggplot(data = processed_data) +
geom_bar(aes(x = Country, y = perc_surveyed_by_country, fill = Dem_edu, text = country_edu_text), stat="identity", size=0.5, color="grey20") +
scale_fill_manual(name="Education", values=c("- PhD/Doctorate" = "#31233bff", "- College degree, bachelor, master" = "#50456cff","- Some College, short continuing education or equivalent" = "#6b6099ff","- Up to 12 years of school " = "#9392b7ff","- Up to 9 years of school" = "#b0b0d1ff","- Up to 6 years of school" = "#bec0d4ff", "- None" = "#f8f8ffff")) +
coord_flip() +
scale_y_continuous(breaks=seq(0,1,0.1),labels = scales::percent_format(accuracy = 1),expand=c(0,0))+
scale_x_discrete(expand=c(0,0))+
labs(x = "Country", y = "% Education") +
theme_classic() +
theme(legend.position="top")

# Sending plots to ui ----


output$PlotlyGender100<-renderPlotly({ ggplotly(pGender100, tooltip = "text") })
output$PlotlyAge<-renderPlotly({ ggplotly(pAge, tooltip = "text") })
output$PlotlyEdu<-renderPlotly({ ggplotly(pEdu, tooltip = "text") })


})
Expand Down
3 changes: 2 additions & 1 deletion ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ui <- fluidPage(
)
)
)
)
),
tabPanel("About")
)
)
Binary file added www/Covidistress2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 03e6c99

Please sign in to comment.