knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(tibble) library(lubridate, warn.conflicts = FALSE) library(ggplot2) library(dplyr, warn.conflicts = FALSE) library(tidyr) library(kableExtra, warn.conflicts = FALSE) library(ec1047) # Suppress summarise info options(dplyr.summarise.inform = FALSE)
str(ecv)
A relatively small number of observations have negative or zero values of disposable income:
ecv %>% filter(ydisp_hh <= 0.0) %>% group_by(year) %>% summarise(n = n())
Drop observations with zero or negative disposable income. Also drop observations from Ceuta y Melilla:
income_db <- ecv %>% filter(ydisp_hh > 0.0, !(region %in% c("CEU", "MEL")))
Mean household income by year:
income_db %>% group_by(year) %>% summarise(y_mean = wtd_mean(ydisp_hh, weight))
Mean disposable income per person by year:
income_db %>% mutate(year = lubridate::make_date(year = year)) %>% group_by(year) %>% summarise(y_mean = wtd_mean(ydisp_cu, weight * people)) %>% ggplot(aes(x = year, y = y_mean)) + geom_line()
Mean disposable income per person by year and region:
y_mean_esp <- income_db %>% group_by(year) %>% summarise(y_mean = wtd_mean(ydisp_cu, weight * people)) %>% mutate(region = "ESP") y_mean_reg <- income_db %>% mutate(region = as.character(region)) %>% group_by(region, year) %>% summarise(y_mean = wtd_mean(ydisp_cu, weight * people)) bind_rows(y_mean_reg, y_mean_esp) %>% pivot_wider(names_from = year, values_from = y_mean) %>% kable(digits = 0) %>% kable_styling(bootstrap_options = c('striped', 'hover'), full_width = FALSE)
Some graphics:
y_mean_reg %>% mutate(year = lubridate::make_date(year = year)) %>% ggplot(aes(x=year, y = y_mean)) + geom_line() + facet_wrap(~ region, nrow = 4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.