Skip to content

Commit

Permalink
Update population indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Jul 30, 2024
1 parent f9ae767 commit 9b5952d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 19 deletions.
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# tidyBdE (development version)

- Update `bde_ind_unemployment_rate()` since the underlying identifier
changed.
- `bde_ind_population()` under review, not providing results as of July 2024.
- Update `bde_ind_unemployment_rate()` and `bde_ind_population()` since the
underlying identifier changed.
- DOI changed to **CRAN** url:
<https://doi.org/10.32614/CRAN.package.tidyBdE>.
- Native encoding when reading the `.csv` files changed to `"latin1"`.

# tidyBdE 0.3.6

Expand Down
16 changes: 7 additions & 9 deletions R/indicators.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,13 @@ bde_ind_gdp_quarterly <- function(series_label = "GDP_quarterly_value", ...) {
#'
#' @export
bde_ind_population <- function(series_label = "Population_Spain", ...) {
# seq_num <- 3078287
#
# econom_ind <- bde_series_load(seq_num, series_label = series_label, ...)
# econom_ind <- econom_ind[!is.na(econom_ind[[2]]), ]
#
# return(econom_ind)

message("Under review")
return(NULL)
# was 3078287
seq_num <- 4637737

econom_ind <- bde_series_load(seq_num, series_label = series_label, ...)
econom_ind <- econom_ind[!is.na(econom_ind[[2]]), ]

return(econom_ind)
}

#' @export
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-indicators.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ test_that("Indicators", {
n7 <- expect_silent(bde_ind_gdp_quarterly())
expect_true(nrow(n7) > 10)

n8 <- expect_silent(bde_ind_population())
expect_true(nrow(n8) > 10)

n9 <- expect_silent(bde_ind_ibex_daily())
expect_true(nrow(n9) > 10)
})
86 changes: 81 additions & 5 deletions vignettes/articles/Main_Macroeconomic_Series.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ br <- seq(nd, Sys.Date(), "6 months")

### Aggregated (last 4 quarters)

```{r echo=FALSE}
```{r gdp_agg, echo=FALSE, fig.alt="GDP of Spain - Aggregated last 4 quarters"}
dataset <- bde_ind_gdp_quarterly(series_label = "data") %>%
drop_na()
Expand Down Expand Up @@ -74,7 +74,7 @@ ggplot(dataset, aes(x = Date, y = data)) +

### Year-on-year variation

```{r echo=FALSE}
```{r gdpyoy, echo=FALSE, fig.alt="GDP of Spain - Year-on-year variation"}
dataset <- bde_ind_gdp_var(series_label = "data") %>%
filter(Date >= nd) %>%
drop_na()
Expand All @@ -101,9 +101,52 @@ ggplot(dataset, aes(x = Date, y = data)) +
theme_tidybde()
```

### GDP per capita

```{r gdppercap, echo=FALSE, fig.alt="GDP per Capita of Spain"}
pop <- bde_ind_population(series_label = "pop")
pib <- bde_ind_gdp_quarterly(series_label = "data")
pib$LastY <- pib$data + lag(pib$data, 1) + lag(pib$data, 2) + lag(pib$data, 3)
pib <- inner_join(pib, pop, by = "Date")
pib <- pib %>% mutate(data = 1000 * LastY / pop)
dataset <- pib %>%
select(Date, data) %>%
filter(Date >= nd) %>%
drop_na()
l <- dataset[nrow(dataset), ]
ggplot(dataset, aes(x = Date, y = data)) +
geom_line(color = col) +
geom_text(
data = l,
size = 3,
aes(label = paste(
x = prettyNum(data, big.mark = " "),
"€\n", format(Date, "%b-%Y")
))
) +
labs(
title = "GDP per capita of Spain",
subtitle = "€",
caption = "Source: BdE"
) +
scale_y_continuous(labels = scales::label_number()) +
scale_x_date(
date_labels = "%b-%Y",
breaks = br
) +
theme_tidybde()
```

## Unemployment Rate

```{r echo=FALSE}
```{r unempl, echo=FALSE, fig.alt="Unemployment rate"}
dataset <- bde_ind_unemployment_rate(series_label = "data") %>%
filter(Date >= nd) %>%
drop_na()
Expand Down Expand Up @@ -132,7 +175,7 @@ ggplot(dataset, aes(x = Date, y = data)) +

## Consumer Price Index

```{r echo=FALSE}
```{r cprix, echo=FALSE, fig.alt="Consumer Price Index"}
dataset <- bde_ind_cpi_var(series_label = "data") %>%
filter(Date >= nd) %>%
drop_na()
Expand Down Expand Up @@ -161,7 +204,7 @@ ggplot(dataset, aes(x = Date, y = data)) +

## Monthly Euribor

```{r echo=FALSE}
```{r eur, echo=FALSE, fig.alt="Monthly Euribor"}
dataset <- bde_ind_euribor_12m_monthly(series_label = "data") %>%
filter(Date >= nd) %>%
drop_na()
Expand All @@ -187,3 +230,36 @@ ggplot(dataset, aes(x = Date, y = data)) +
) +
theme_tidybde()
```

## Population

```{r pop, echo=FALSE, fig.alt="Population in thousands"}
dataset <- bde_ind_population(series_label = "data") %>%
filter(Date >= nd) %>%
drop_na()
l <- dataset[nrow(dataset), ]
ggplot(dataset, aes(x = Date, y = data)) +
geom_line(color = col) +
geom_text(
data = l,
size = 3,
aes(label = paste(
x = prettyNum(data, big.mark = " "),
"\n", format(Date, "%b-%Y")
))
) +
labs(
title = "Population of Spain",
subtitle = "thousands",
caption = "Source: BdE"
) +
scale_x_date(
date_labels = "%b-%Y",
breaks = br
) +
scale_y_continuous(labels = scales::label_number()) +
theme_tidybde()
```
9 changes: 7 additions & 2 deletions vignettes/articles/Series_Index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ series_clean <- series %>%
Tipo_de_variable,
Fecha_de_la_primera_observacion,
Fecha_de_la_ultima_observacion,
Frecuencia_de_la_serie
)
Frecuencia_de_la_serie, Fuente
) %>%
as_tibble()
names(series_clean) <- gsub("_", " ", names(series_clean))
library(reactable)
Expand All @@ -59,6 +63,7 @@ library(reactable)
reactable(series_clean,
filterable = TRUE,
searchable = TRUE,
resizable = TRUE,
showPageSizeOptions = TRUE,
striped = TRUE,
defaultColDef = colDef(
Expand Down

0 comments on commit 9b5952d

Please sign in to comment.