Skip to content

Instantly share code, notes, and snippets.

@psobczyk
Created August 15, 2017 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psobczyk/34f282019be7c3a66901bdaa1935c2bf to your computer and use it in GitHub Desktop.
Save psobczyk/34f282019be7c3a66901bdaa1935c2bf to your computer and use it in GitHub Desktop.
# data can be downloaded from http://ghdx.healthdata.org/gbd-2015
obesity <- read.csv("IHME_GBD_2015_OBESITY_PREVALENCE_1980_2015_1/IHME_GBD_2015_OBESITY_PREVALENCE_1980_2015_Y2017M06D12.CSV")
obesity %>%
filter(location_name %in% c("United States", "Poland", "Sweden"),
metric == "Percent",
sex == "Both",
age_group_name %in% c('15 to 19', '20 to 24',
'30 to 34', '35 to 39',
'55 to 59', '60 to 64')) %>%
mutate(location_name = forcats::fct_recode(location_name, "Polska" = "Poland",
"Szwecja" = "Sweden",
'USA' = "United States"),
age_group_name = gsub(pattern = "to", repl = "-", age_group_name)) %>%
select(-measure, -location_id, - sex_id, - age_group_id) %>%
ggplot(aes(x = year_id, y = mean, group = age_group_name, color = age_group_name)) +
geom_line() +
scale_color_brewer(type = "qual", palette = "Paired") +
scale_y_continuous(labels = scales::percent) +
facet_wrap(~location_name) +
guides(color = guide_legend(title = 'Wiek', override.aes = aes(size = 6))) +
labs(title = "Procent osób otyłych w wybranych krajach") +
theme_fivethirtyeight(base_size = 20, base_family = "Helvetica Neue Light") +
theme(plot.title = element_text(hjust = 0.5),
panel.background = element_rect(fill="white"),
plot.background = element_rect(fill="white"),
legend.background = element_rect(fill="white"),
legend.key = element_rect(fill="white"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment