knitr::opts_chunk$set(collapse = TRUE, comment = "#>", cache = TRUE)
library("senadoRES")
library("dplyr")
library("ggplot2")

Senadores

This function return the members of the Senate:

ts <- senadores()
head(ts)

We can see the increase of females on the Senate along the legislatures:

ts %>%
    group_by(legislatura) %>%
    count(sex) %>%
    mutate(total = sum(n)) %>%
    filter(!is.na(sex)) %>%
    mutate(ratio = n/total) %>%
    filter(sex != "male") %>% 
    ggplot() +
    geom_point(aes(legislatura, ratio, col = sex, shape = sex), size = 3) +
    geom_hline(yintercept = 0.5, linetype = 2, col = "red") +
    scale_x_continuous(breaks = seq_len(15)) +
    scale_y_continuous(breaks = seq(from = 0, to = 0.7, by = .1),
                       expand = expansion(add = c(0, 0.01)), limits = c(0, NA)) +
    theme_minimal() +
    labs(title = "Ratio of women", x  = "Legislatura", y = "Ratio of women")

Documents

The Senate has its own publication with different types of documents. The three main documents are a document, the boletin and the sumario. All recognized documents have a code named CSV. You can create the CSV with:

document_csv(legislatura = 14, sesion = 1, number = 1)
boletin_csv(legislatura = 14, sesion = 1)
sumario_csv(legislatura = 14, sesion = 1)

If you found a CSV and you aren't sure if a code is valid with check_code(). Once we have a valid CSV we can retrieve the information about the document:

boletin_csv <- boletin_csv(14, 3)
b <-  boletin(boletin_csv)
head(b[, c(1:14, 16)])

Here I omitted a column because the functions also return the text explaining the document and it is a bit verbose to show.

sumario_csv <- sumario_csv(legislatura = 14, sesion = 1)
s <- sumario(sumario_csv)
head(s)

Both of them refer to a session, but they do not provide the same information. To make it easier to retrieve all information possible from a session you can do this:

bs <- boletin_sumario(legislatura = 14, sesion = 3)
head(bs)

If you are interested in a single document you can then use:

document_csv <- "BOCG_D_14_3_15"
d <- documento(document_csv)
d[, 1:15]

Plenarias

As you need to know how many plenary sessions were done you can check them with:

head(plenarias(10))

Note that this information is only available from the X legislature onward

s <- lapply(10:14, plenarias)
sessions <- do.call(rbind, s)
ggplot(sessions) +
    stat_sum(aes(sesionLegislatura, sesionHoraInicio, 
                 fill = after_stat(n), size = 1), geom = "tile") +
    guides(size = "none") +
    theme_minimal() +
    labs(title = "Hour of sessions", x = "Legislature", y = "Starting hour",
         fill = "Sessions") +
    scale_y_continuous(breaks = 1:19)

So most of the times they meet at the afternoon.

If you want more detailed information of each session you can use the fichUrlDetalleSesion details:

details <- detalles(paste0("https://www.senado.es", sessions$fichUrlDetalleSesion[3]))
details[1:5, c("asunto_id", "asunto_hora_inicio", "asunto_hora_fin", "punto_literal", "intervencion_orador_desc", "intervencion_orador_idWeb")]

This will help you know who talked, how long about which topics and which documents got referenced.

Grupos

If you are interested on the political groups composition at certain legislature:

g <- grupos(12)
head(g)

Note that the record in this case starts from the XII legislature.

Laws

As a legislative chamber one of the most important duties is to approve and change laws- We can see how many got approved (note that some are closer on time or are still on the process of being approved):

lex14 <- leyes(14)
head(lex14)

Organization chart

If you want to know who works where and their position you can check it out with:

head(organigrama(13))

Unfortunately this doesn't go back in time, I think it only shows the current



rOpenSpain/senadoRES documentation built on Dec. 26, 2024, 8:18 p.m.