I.何をする?

次のデータを集計します。

voteview.com

Rvoteviewを使用します。

https://github.com/voteview/Rvoteview

II.Voteview.comについて

108,335の米国上院、下院の投票結果が記録れています。

トップページには、直近の上院の法案の値投票結果が表示されています。

クリックすると法案番号、投票結果、法案の内容などの情報だけではなく、議員選出州ごとの法案の賛否を示した米国地図、賛否のグラフ、議員ごとの賛否のリストが表示されます。

III.Rvoteviewの使い方

1.COVID-19関連法案を調べる

検索すると773件ヒットしました。 検索結果は、項目名のついたリストですので項目名を表示します。

# ライブラリのインポート
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
## ✓ tibble  3.0.4     ✓ dplyr   1.0.5
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(Rvoteview)
## 
## Attaching package: 'Rvoteview'
## The following object is masked from 'package:ggplot2':
## 
##     %+%
# 検索
res <- voteview_search("COVID-19")
## Query 'COVID-19' returned 773 rollcalls...
# 検索結果リストの項目名を表示
names(res)
##  [1] "id"                "congress"          "chamber"          
##  [4] "rollnumber"        "date"              "yea"              
##  [7] "nay"               "support"           "vote_result"      
## [10] "short_description" "question"          "text"             
## [13] "score"             "bill_number"       "sponsor"          
## [16] "key_flags"         "codes.Peltzman"    "codes.Clausen"    
## [19] "codes.Issue"

適当な項目を選んで、データ一覧のはじめの6件を表示します。

res[c("id", "congress", "chamber", "date", "support", "question", "bill_number")] %>% 
  head()
##          id congress chamber       date support
## 1 RH1160892      116   House 2020-09-17   59.71
## 2 RH1090596      109   House 2005-11-17   99.53
## 3 RH1160878      116   House 2020-08-22   57.36
## 4 RH1170087      117   House 2021-03-17   96.61
## 5 RH1160879      116   House 2020-08-22   57.36
## 6 RH0650184       65   House 1918-08-24   43.50
##                                               question bill_number
## 1                        On Agreeing to the Resolution     HRES908
## 2 On Motion to Suspend the Rules and Agree, as Amended     HRES500
## 3                    On Ordering the Previous Question    HRES1092
## 4  On Motion to Suspend the Rules and Pass, as Amended      HR1651
## 5                        On Agreeing to the Resolution    HRES1092
## 6                                                 <NA>     HR12731

Not completed.