<- 'https://theunitedstates.io/congress-legislators/legislators-current.csv'
leg_dets <- read.csv((url(leg_dets)), stringsAsFactors = FALSE)
details $birthday <- as.Date(details$birthday)
details
<- c('bioguide_id',
k1 'party',
'birthday',
'gender',
'senate_class',
'twitter',
'wikipedia_id')
A quick look at age and generation distributions in the 117th US House of Representatives.
1 Current US lawmakers
<- Rvoteview::download_metadata(type = 'members',
nominate #chamber = 'house',
congress = '117') |>
subset(chamber != 'President')
<- c('bioguide_id',
k2 'congress',
'chamber',
'district_code',
'state_abbrev',
'bioname',
'nominate_dim1',
'nominate_dim2')
<- merge(x = details[,k1],
members y = nominate[,k2],
by = "bioguide_id",
all.y = TRUE)
$age <- trunc(as.numeric(difftime(Sys.Date(),
members$birthday,
membersunits = "days")) / 365.25)
2 American Generations
<- c(#'Missionary',
generation #'Lost',
'Greatest',
'Silent',
'Boomers',
'Gen X',
'Millenials',
'Gen Z',
'Post-Z')
<- c(#'1860-01-01',
start_yr #'1883-01-01',
'1901-01-01',
'1928-01-01',
'1946-01-01',
'1965-01-01',
'1981-01-01',
'1997-01-01',
'2013-01-01')
<- c(#'1882-01-01',
end_yr #'1900-01-01',
'1927-12-31',
'1945-12-31',
'1964-12-31',
'1980-12-31',
'1996-12-31',
'2012-12-31',
'2028-12-31')
Note that zero members of Gen Z are old enough to serve in the US House of Representatives– and all Millenials now are.
<- data.frame(generation = factor(generation,
pgs levels = unique(generation)),
start = as.Date(start_yr),
end = as.Date(end_yr))
$youngest <- trunc(as.numeric(difftime(Sys.Date(),
pgs$end,
pgsunits = "days")) / 365.25)
|> knitr::kable() pgs
generation | start | end | youngest |
---|---|---|---|
Greatest | 1901-01-01 | 1927-12-31 | 94 |
Silent | 1928-01-01 | 1945-12-31 | 76 |
Boomers | 1946-01-01 | 1964-12-31 | 57 |
Gen X | 1965-01-01 | 1980-12-31 | 41 |
Millenials | 1981-01-01 | 1996-12-31 | 25 |
Gen Z | 1997-01-01 | 2012-12-31 | 9 |
Post-Z | 2013-01-01 | 2028-12-31 | -6 |
2.1 Assign generations
$generation <- pgs$generation[
membersfindInterval(x = members$birthday, vec = pgs$start)]
library(dplyr)
|>
members filter(chamber == 'House' & !is.na(age)) |>
count(party, gender, generation) |>
::spread(generation, n) |>
tidyr::kable() knitr
party | gender | Silent | Boomers | Gen X | Millenials |
---|---|---|---|---|---|
Democrat | F | 11 | 40 | 34 | 5 |
Democrat | M | 9 | 75 | 37 | 9 |
Republican | F | 2 | 13 | 11 | 6 |
Republican | M | 3 | 97 | 65 | 13 |
2.2 Dotplot
library(ggplot2)
<- members |> filter(chamber == 'House' & !is.na(age)) |>
hs0 arrange(generation)
|>
hs0 ggplot() +
geom_dotplot(aes(x = age,
color = gender,
fill = gender,),
method="histodot",
dotsize = .9,
binpositions = 'all',
stackratio = 1.3,
stackgroups=TRUE,
binwidth = 1) +
geom_vline(xintercept = pgs$youngest[2:5] - 0.5,
linetype =2,
color = 'black',
size = .25) +
geom_text(data = pgs[2:5,],
aes(x = youngest + 2.25,
y = 0.95,
label = generation),
size = 3) +
theme_minimal() +
::scale_fill_economist() +
ggthemes::scale_color_economist() +
ggthemes
facet_wrap(~party, nrow = 2) +
theme(legend.position = "bottom",
axis.title.y=element_blank(),
axis.text.y=element_blank()) +
#ylim (0, .5) +
labs(title = "Age distribution of the 117th House by party")
3 Parliamentary Plot
A real nice function below for drawing ‘parliamentary graphs’ – stolen from this SO post.
<- function(N, M, r0 = 2){
seats <- seq(r0, 1, len=M)
radii <- numeric(M)
counts = do.call(rbind,
pts lapply(1:M, function(i){
<<- round(N*radii[i]/sum(radii[i:M]))
counts[i] <- seq(0, pi, len = counts[i])
theta <<- N - counts[i]
N data.frame(x=radii[i]*cos(theta), y=radii[i]*sin(theta), r=i,
theta=theta)}))
= pts[order(-pts$theta,-pts$r),]
pts pts}
<- seats(430,8) |> mutate(Generation = hs0$generation)
sx
|>
sx ggplot() +
geom_point(aes(x, y,
color = Generation),
size = 3) +
::scale_color_stata()+
ggthemestheme_minimal()+
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
legend.position = 'bottom',
plot.title = element_text(size=12)
+
) labs(title="Composition of 117th US House by Generation")