├── R ├── .Rapp.history ├── .DS_Store ├── sysdata.rda ├── ggparliament_package.R ├── data.R ├── geom_highlight_government.R ├── geom_overhang_seats.R ├── helper_funcs.R ├── theme_ggparliament.R ├── geom_emphasize_parliamentarians.R ├── geom_parliament_seats.R ├── geom_parliament_bar.R ├── draw_totalseats.R ├── draw_majoritythreshold.R ├── draw_partylabels.R └── parliament_data.R ├── LICENSE ├── data ├── .DS_Store └── election_data.rda ├── tests ├── .DS_Store ├── testdata │ └── usa_data.rda ├── testthat.R └── testthat │ └── test_parliament_data.R ├── docs ├── docs │ ├── .DS_Store │ └── figure │ │ ├── unnamed-chunk-11-1.png │ │ ├── unnamed-chunk-6-1.png │ │ ├── unnamed-chunk-7-1.png │ │ ├── unnamed-chunk-8-1.png │ │ └── unnamed-chunk-9-1.png ├── reference │ ├── Rplot001.png │ ├── figures │ │ ├── au_rep.png │ │ ├── commons.png │ │ ├── senate.png │ │ ├── us_rep.png │ │ ├── bundestag.png │ │ ├── HexSticker.png │ │ ├── unnamed-chunk-4-1.png │ │ ├── unnamed-chunk-5-1.png │ │ ├── unnamed-chunk-6-1.png │ │ ├── unnamed-chunk-7-1.png │ │ └── unnamed-chunk-9-1.png │ ├── draw_totalseats-1.png │ ├── draw_partylabels-1.png │ ├── theme_ggparliament-1.png │ ├── geom_overhang_seats-1.png │ ├── geom_parliament_bar-1.png │ ├── draw_majoritythreshold-1.png │ ├── geom_parliament_seats-1.png │ ├── geom_highlight_government-1.png │ ├── geom_emphasize_parliamentarians-1.png │ ├── ggparliament-package.html │ ├── ggplot2-ggproto.html │ └── election_data.html ├── figure │ ├── unnamed-chunk-11-1.png │ ├── unnamed-chunk-6-1.png │ ├── unnamed-chunk-7-1.png │ ├── unnamed-chunk-8-1.png │ └── unnamed-chunk-9-1.png ├── articles │ ├── hanging_seats_7_files │ │ └── figure-html │ │ │ └── unnamed-chunk-1-1.png │ ├── label-parties_2_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-1-1.png │ │ │ ├── unnamed-chunk-2-1.png │ │ │ └── unnamed-chunk-3-1.png │ ├── 2_label-parties_2_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-1-1.png │ │ │ ├── unnamed-chunk-2-1.png │ │ │ └── unnamed-chunk-3-1.png │ ├── 7_hanging_seats_7_files │ │ └── figure-html │ │ │ └── unnamed-chunk-1-1.png │ ├── b_label-parties_2_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-1-1.png │ │ │ ├── unnamed-chunk-2-1.png │ │ │ └── unnamed-chunk-3-1.png │ ├── g_hanging_seats_7_files │ │ └── figure-html │ │ │ └── unnamed-chunk-1-1.png │ ├── 5_facet-parliament_5_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ └── unnamed-chunk-6-1.png │ ├── arrange_parliament_8_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ └── unnamed-chunk-4-1.png │ ├── e_facet-parliament_5_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ └── unnamed-chunk-6-1.png │ ├── facet-parliament_5_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ └── unnamed-chunk-6-1.png │ ├── 8_arrange_parliament_8_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ └── unnamed-chunk-4-1.png │ ├── h_arrange_parliament_8_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ └── unnamed-chunk-4-1.png │ ├── highlight-government_4_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-3-1.png │ │ │ └── unnamed-chunk-5-1.png │ ├── 4_highlight-government_4_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-3-1.png │ │ │ └── unnamed-chunk-5-1.png │ ├── basic-parliament-plots_1_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-10-1.png │ │ │ ├── unnamed-chunk-11-1.png │ │ │ ├── unnamed-chunk-12-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ └── unnamed-chunk-8-1.png │ ├── d_highlight-government_4_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-3-1.png │ │ │ └── unnamed-chunk-5-1.png │ ├── draw-majority-threshold_3_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-1-1.png │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ └── unnamed-chunk-4-1.png │ ├── 1_basic-parliament-plots_1_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-10-1.png │ │ │ ├── unnamed-chunk-11-1.png │ │ │ ├── unnamed-chunk-12-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ └── unnamed-chunk-8-1.png │ ├── 3_draw-majority-threshold_3_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-1-1.png │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ └── unnamed-chunk-4-1.png │ ├── a_basic-parliament-plots_1_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-10-1.png │ │ │ ├── unnamed-chunk-11-1.png │ │ │ ├── unnamed-chunk-12-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ └── unnamed-chunk-8-1.png │ ├── c_draw-majority-threshold_3_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-1-1.png │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ └── unnamed-chunk-4-1.png │ ├── 6_emphasize_parliamentarians_6_files │ │ └── figure-html │ │ │ └── unnamed-chunk-1-1.png │ ├── emphasize_parliamentarians_6_files │ │ └── figure-html │ │ │ └── unnamed-chunk-1-1.png │ ├── f_emphasize_parliamentarians_6_files │ │ └── figure-html │ │ │ └── unnamed-chunk-1-1.png │ └── index.html ├── pkgdown.yml ├── link.svg ├── bootstrap-toc.css ├── docsearch.js ├── pkgdown.js ├── sitemap.xml ├── bootstrap-toc.js ├── LICENSE-text.html ├── 404.html ├── CONTRIBUTING.html └── authors.html ├── vignettes ├── .DS_Store ├── f_emphasize_parliamentarians_6.Rmd ├── d_highlight-government_4.Rmd ├── g_hanging_seats_7.Rmd ├── b_label-parties_2.Rmd ├── e_facet-parliament_5.Rmd ├── h_arrange_parliament_8.Rmd └── c_draw-majority-threshold_3.Rmd ├── man ├── figures │ ├── .DS_Store │ ├── au_rep.png │ ├── commons.png │ ├── senate.png │ ├── us_rep.png │ ├── HexSticker.png │ ├── bundestag.png │ ├── unnamed-chunk-4-1.png │ ├── unnamed-chunk-5-1.png │ ├── unnamed-chunk-6-1.png │ ├── unnamed-chunk-7-1.png │ └── unnamed-chunk-9-1.png ├── ggparliament-package.Rd ├── ggplot2-ggproto.Rd ├── calc_coordinates.Rd ├── election_data.Rd ├── geom_parliament_bar.Rd ├── theme_ggparliament.Rd ├── draw_totalseats.Rd ├── geom_highlight_government.Rd ├── parliament_data.Rd ├── geom_overhang_seats.Rd ├── draw_majoritythreshold.Rd ├── geom_emphasize_parliamentarians.Rd ├── geom_parliament_seats.Rd └── draw_partylabels.Rd ├── paper ├── ggparliament_layouts.png ├── paper.bib └── paper.md ├── .gitignore ├── .Rbuildignore ├── Makefile ├── NAMESPACE ├── CONTRIBUTING.md ├── cran-comments.md ├── NEWS.md ├── DESCRIPTION └── README.md /R/.Rapp.history: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2018 2 | COPYRIGHT HOLDER: Robert Hickman -------------------------------------------------------------------------------- /R/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/R/.DS_Store -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/R/sysdata.rda -------------------------------------------------------------------------------- /data/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/data/.DS_Store -------------------------------------------------------------------------------- /tests/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/tests/.DS_Store -------------------------------------------------------------------------------- /docs/docs/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/docs/.DS_Store -------------------------------------------------------------------------------- /vignettes/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/vignettes/.DS_Store -------------------------------------------------------------------------------- /man/figures/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/.DS_Store -------------------------------------------------------------------------------- /data/election_data.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/data/election_data.rda -------------------------------------------------------------------------------- /man/figures/au_rep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/au_rep.png -------------------------------------------------------------------------------- /man/figures/commons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/commons.png -------------------------------------------------------------------------------- /man/figures/senate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/senate.png -------------------------------------------------------------------------------- /man/figures/us_rep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/us_rep.png -------------------------------------------------------------------------------- /man/figures/HexSticker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/HexSticker.png -------------------------------------------------------------------------------- /man/figures/bundestag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/bundestag.png -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /tests/testdata/usa_data.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/tests/testdata/usa_data.rda -------------------------------------------------------------------------------- /paper/ggparliament_layouts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/paper/ggparliament_layouts.png -------------------------------------------------------------------------------- /docs/figure/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/figure/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/figure/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/figure/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/figure/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/figure/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/figure/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/figure/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/figure/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/figure/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/reference/figures/au_rep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/au_rep.png -------------------------------------------------------------------------------- /docs/reference/figures/commons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/commons.png -------------------------------------------------------------------------------- /docs/reference/figures/senate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/senate.png -------------------------------------------------------------------------------- /docs/reference/figures/us_rep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/us_rep.png -------------------------------------------------------------------------------- /man/figures/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /man/figures/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /man/figures/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /man/figures/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /man/figures/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/man/figures/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/reference/draw_totalseats-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/draw_totalseats-1.png -------------------------------------------------------------------------------- /docs/reference/figures/bundestag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/bundestag.png -------------------------------------------------------------------------------- /docs/docs/figure/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/docs/figure/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/docs/figure/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/docs/figure/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/docs/figure/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/docs/figure/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/docs/figure/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/docs/figure/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/docs/figure/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/docs/figure/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/reference/draw_partylabels-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/draw_partylabels-1.png -------------------------------------------------------------------------------- /docs/reference/figures/HexSticker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/HexSticker.png -------------------------------------------------------------------------------- /docs/reference/theme_ggparliament-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/theme_ggparliament-1.png -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | Sys.setenv(R_TESTS = "") 2 | library(testthat) 3 | library(ggparliament) 4 | 5 | test_check("ggparliament") 6 | -------------------------------------------------------------------------------- /docs/reference/geom_overhang_seats-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/geom_overhang_seats-1.png -------------------------------------------------------------------------------- /docs/reference/geom_parliament_bar-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/geom_parliament_bar-1.png -------------------------------------------------------------------------------- /docs/reference/draw_majoritythreshold-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/draw_majoritythreshold-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/figures/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/reference/geom_parliament_seats-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/geom_parliament_seats-1.png -------------------------------------------------------------------------------- /docs/reference/geom_highlight_government-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/geom_highlight_government-1.png -------------------------------------------------------------------------------- /R/ggparliament_package.R: -------------------------------------------------------------------------------- 1 | #' ggparliament 2 | #' @name ggparliament-package 3 | #' @keywords "_PACKAGE" 4 | #' 5 | #' @import ggplot2 6 | #' 7 | NULL 8 | -------------------------------------------------------------------------------- /docs/reference/geom_emphasize_parliamentarians-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/reference/geom_emphasize_parliamentarians-1.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Meta 2 | doc 3 | .Rproj.user 4 | .Rhistory 5 | .RData 6 | .Ruserdata 7 | ggparliament.Rproj 8 | README.html 9 | inst/doc 10 | inst/figure.DS_Store 11 | .DS_Store 12 | -------------------------------------------------------------------------------- /docs/articles/hanging_seats_7_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/hanging_seats_7_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/label-parties_2_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/label-parties_2_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/label-parties_2_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/label-parties_2_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/label-parties_2_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/label-parties_2_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^Meta$ 2 | ^doc$ 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | ^.*\.yml$ 6 | Makefile 7 | ^README\.html$ 8 | ^README\.Rmd$ 9 | ^README-.*\.png$ 10 | ^cran-comments\.md$ 11 | 12 | -------------------------------------------------------------------------------- /docs/articles/2_label-parties_2_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/2_label-parties_2_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/2_label-parties_2_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/2_label-parties_2_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/2_label-parties_2_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/2_label-parties_2_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/7_hanging_seats_7_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/7_hanging_seats_7_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/b_label-parties_2_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/b_label-parties_2_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/b_label-parties_2_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/b_label-parties_2_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/b_label-parties_2_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/b_label-parties_2_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/g_hanging_seats_7_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/g_hanging_seats_7_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/5_facet-parliament_5_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/5_facet-parliament_5_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/5_facet-parliament_5_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/5_facet-parliament_5_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/5_facet-parliament_5_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/5_facet-parliament_5_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/arrange_parliament_8_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/arrange_parliament_8_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/arrange_parliament_8_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/arrange_parliament_8_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/arrange_parliament_8_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/arrange_parliament_8_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/e_facet-parliament_5_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/e_facet-parliament_5_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/e_facet-parliament_5_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/e_facet-parliament_5_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/e_facet-parliament_5_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/e_facet-parliament_5_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/facet-parliament_5_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/facet-parliament_5_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/facet-parliament_5_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/facet-parliament_5_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/facet-parliament_5_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/facet-parliament_5_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/8_arrange_parliament_8_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/8_arrange_parliament_8_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/8_arrange_parliament_8_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/8_arrange_parliament_8_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/8_arrange_parliament_8_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/8_arrange_parliament_8_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/h_arrange_parliament_8_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/h_arrange_parliament_8_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/h_arrange_parliament_8_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/h_arrange_parliament_8_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/h_arrange_parliament_8_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/h_arrange_parliament_8_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/highlight-government_4_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/highlight-government_4_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/highlight-government_4_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/highlight-government_4_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/4_highlight-government_4_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/4_highlight-government_4_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/4_highlight-government_4_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/4_highlight-government_4_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/basic-parliament-plots_1_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/d_highlight-government_4_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/d_highlight-government_4_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/d_highlight-government_4_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/d_highlight-government_4_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/draw-majority-threshold_3_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/draw-majority-threshold_3_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/draw-majority-threshold_3_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/draw-majority-threshold_3_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/draw-majority-threshold_3_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/draw-majority-threshold_3_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/draw-majority-threshold_3_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/draw-majority-threshold_3_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/1_basic-parliament-plots_1_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/3_draw-majority-threshold_3_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/3_draw-majority-threshold_3_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/3_draw-majority-threshold_3_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/3_draw-majority-threshold_3_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/3_draw-majority-threshold_3_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/3_draw-majority-threshold_3_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/3_draw-majority-threshold_3_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/3_draw-majority-threshold_3_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/a_basic-parliament-plots_1_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/c_draw-majority-threshold_3_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/c_draw-majority-threshold_3_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/c_draw-majority-threshold_3_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/c_draw-majority-threshold_3_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/c_draw-majority-threshold_3_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/c_draw-majority-threshold_3_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/c_draw-majority-threshold_3_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/c_draw-majority-threshold_3_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/6_emphasize_parliamentarians_6_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/6_emphasize_parliamentarians_6_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/emphasize_parliamentarians_6_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/emphasize_parliamentarians_6_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/f_emphasize_parliamentarians_6_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zmeers/ggparliament/HEAD/docs/articles/f_emphasize_parliamentarians_6_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /man/ggparliament-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggparliament_package.R 3 | \name{ggparliament-package} 4 | \alias{ggparliament-package} 5 | \title{ggparliament} 6 | \description{ 7 | ggparliament 8 | } 9 | \keyword{"_PACKAGE"} 10 | -------------------------------------------------------------------------------- /man/ggplot2-ggproto.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/geom_parliament_seats.R 3 | \docType{data} 4 | \name{GeomParliamentSeats} 5 | \alias{GeomParliamentSeats} 6 | \title{ggplot2-ggproto} 7 | \description{ 8 | ggplot2-ggproto 9 | } 10 | \keyword{datasets} 11 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 3.1.11 2 | pkgdown: 2.0.7 3 | pkgdown_sha: ~ 4 | articles: 5 | a_basic-parliament-plots_1: a_basic-parliament-plots_1.html 6 | b_label-parties_2: b_label-parties_2.html 7 | c_draw-majority-threshold_3: c_draw-majority-threshold_3.html 8 | d_highlight-government_4: d_highlight-government_4.html 9 | e_facet-parliament_5: e_facet-parliament_5.html 10 | f_emphasize_parliamentarians_6: f_emphasize_parliamentarians_6.html 11 | g_hanging_seats_7: g_hanging_seats_7.html 12 | h_arrange_parliament_8: h_arrange_parliament_8.html 13 | last_built: 2024-05-19T09:38Z 14 | 15 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | pkg = $(shell basename $(CURDIR)) 2 | 3 | all: build 4 | 5 | man/*: R/* 6 | Rscript -e "devtools::document()" 7 | 8 | README.md: README.Rmd 9 | Rscript -e "knitr::knit('README.Rmd')" 10 | 11 | README.html: README.md 12 | pandoc -o README.html README.md 13 | 14 | ../$(pkg)*.tar.gz: DESCRIPTION README.md man/* 15 | cd ../ && R CMD build $(pkg) 16 | 17 | build: ../$(pkg)*.tar.gz 18 | 19 | check: ../$(pkg)*.tar.gz 20 | cd ../ && R CMD check $(pkg)*.tar.gz 21 | rm ../$(pkg)*.tar.gz 22 | 23 | install: ../$(pkg)*.tar.gz 24 | cd ../ && R CMD INSTALL $(pkg)*.tar.gz 25 | rm ../$(pkg)*.tar.gz 26 | -------------------------------------------------------------------------------- /tests/testthat/test_parliament_data.R: -------------------------------------------------------------------------------- 1 | library(ggparliament) 2 | library(testthat) 3 | library(ggplot2) 4 | library(dplyr) 5 | 6 | test_data <- readRDS("../testdata/usa_data.rda") 7 | result <- parliament_data(election_data = test_data, parl_rows = 8, party_seats = test_data$seats, type = "semicircle") 8 | 9 | 10 | test_that("Check that the number of expanded observations is identical to the sum of the seats", { 11 | expect_equal(sum(test_data$seats), nrow(result)) 12 | }) 13 | 14 | test_that("Check that the resulting output contains 12 headers", { 15 | expect_equal(colnames(result), c("year", "country", "house", "party_long", "party_short", "seats", "government", "colour", "x", "y", "row", "theta")) 16 | }) 17 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(ggplot_add,emphMPs) 4 | S3method(ggplot_add,hangingseats) 5 | S3method(ggplot_add,highlight) 6 | S3method(ggplot_add,majorityLine) 7 | S3method(ggplot_add,parliamentBar) 8 | S3method(ggplot_add,partyLabels) 9 | S3method(ggplot_add,totalLabels) 10 | export(GeomParliamentSeats) 11 | export(draw_majoritythreshold) 12 | export(draw_partylabels) 13 | export(draw_totalseats) 14 | export(geom_emphasize_parliamentarians) 15 | export(geom_highlight_government) 16 | export(geom_overhang_seats) 17 | export(geom_parliament_bar) 18 | export(geom_parliament_seats) 19 | export(parliament_data) 20 | export(theme_ggparliament) 21 | import(ggplot2) 22 | importFrom(ggplot2,ggplot_add) 23 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to `ggparliament` 2 | 3 | 4 | Thank you for any contributions. We welcome contributions from all, regardless of your programming experience. 5 | 6 | ## Types of contributions 7 | 8 | We would love to hear from anyone who is willing to provide their time and help. 9 | 10 | Here is a non-exhaustive list of things that we might need help with: 11 | 1. Election data 12 | 2. Adding additional information about legislatures or electoral systems 13 | 3. Extending interactive `ggparliament` objects 14 | 4. Writing tutorials or vignettes 15 | 5. Fix bugs 16 | 17 | 18 | ## How to contribute code or data 19 | 20 | 1. Fork this repository 21 | 2. Make your changes and commit to your GitHub fork. 22 | 3. Open an issue here and submit a pull request. 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | # Revise and Resubmit- 17th September 2018 2 | ## Summary 3 | 4 | ## Test Environments 5 | 6 | 7 | ## spell_check results 8 | 9 | Some Anglicisms (colour instead of color), otherwise mostly abbreviations or documentation jargon (e.g. VignetteEncoding) 10 | 11 | ## R CMD check results 12 | 13 | There are: 0 errors, 0 warnings, 1 note. 14 | 15 | * checking CRAN incoming feasibility ... NOTE 16 | Maintainer: 'Robert Hickman ' 17 | 18 | New submission 19 | 20 | ## check_rhub results 21 | 22 | W checking top-level files 23 | Conversion of 'README.md' failed: 24 | pandoc.exe: Could not fetch https://travis-ci.org/RobWHickman/ggparliament.png 25 | 26 | potential fix at https://github.com/r-lib/usethis/issues/318 but seems to pass all other checks? 27 | 28 | 29 | otherwise no more errors/warnings/notes -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /man/calc_coordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helper_funcs.R 3 | \name{calc_coordinates} 4 | \alias{calc_coordinates} 5 | \title{A function that calculates the coordinates of parliamentary seats in incomplete circular parliaments 6 | E.g. The US (semicircle) and Australian (horseshoe) shaped parliaments} 7 | \usage{ 8 | calc_coordinates(N, M, limits, segment = 0.5) 9 | } 10 | \arguments{ 11 | \item{N}{the total of number of seats} 12 | 13 | \item{M}{the number of rows in parliament} 14 | 15 | \item{limits}{the limits to seq the radii between- controls the 'shape' of the parliament} 16 | 17 | \item{segment}{the percentage of a full circle for the final plot- defaults to 0.5 (a semicircle)} 18 | } 19 | \description{ 20 | A function that calculates the coordinates of parliamentary seats in incomplete circular parliaments 21 | E.g. The US (semicircle) and Australian (horseshoe) shaped parliaments 22 | } 23 | \author{ 24 | Zoe Meers, Rob Hickman 25 | } 26 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # ggparliament 3.1.7 2 | ## 07/2025 3 | - Added new elections data for Canada. 4 | - Updated election dataset documentation. 5 | 6 | # ggparliament 3.1.6 7 | ## 05/2024 8 | - Updated DESCRIPTION, citation and README files. 9 | - Dropped old figure files and README_files folder. 10 | 11 | # ggparliament 3.1.5 12 | ## 04/2024 13 | - Fixed CRAN error in package vignette; package resubmitted. 14 | - Added `pkgdown` documentation in the docs subdirectory. 15 | 16 | # ggparliament 2.1.5 17 | ## 04/2021 18 | - Added new election data for the US, the UK, and Australia 19 | 20 | ## 04/2019 21 | - Added revised JOSS paper 22 | 23 | # ggparliament 2.0.1 24 | ## 02/2019 25 | - Updated small errors in data 26 | - Included data from South America (Chile) 27 | - Added JOSS paper to paper folder 28 | - Added size parameter to geom_emphasize_parliamentarians 29 | 30 | ## 09/2018 31 | 32 | - rewritten package from ground up to replace original functions developed by Thomas Leeper 33 | - vignettes for various functions added 34 | - initial submission to CRAN -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' Election data from 7 countries 2 | #' 3 | #' A dataset containing election results for parliamentary houses from 4 | #' Australia, Canada, Chile, Germany, Russia, UK, and USA. The variables are as follows: 5 | #' 6 | #' \itemize{ 7 | #' \item year. The year of the election (1990-2025) 8 | #' \item country. The country the election took place within (Australia, Canada, Chile, Germany, Russia, UK, and USA) 9 | #' \item house. The parliamentary house of the election 10 | #' \item party_long. The full name of a party which had elected representatives 11 | #' \item party_short. The abbreviated name of a party which had elected representatives 12 | #' \item seats. The number of seats won by each party 13 | #' \item government. Whether or not that party was a part of the government following the election (1, 0) 14 | #' \item colour. A hex code indicating the colours of each party 15 | #' } 16 | #' 17 | #' @docType data 18 | #' @keywords datasets 19 | #' @name election_data 20 | #' @usage data(election_data) 21 | #' @format A tibble with 312 rows and 8 variables 22 | "election_data" 23 | -------------------------------------------------------------------------------- /man/election_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{election_data} 5 | \alias{election_data} 6 | \title{Election data from 7 countries} 7 | \format{ 8 | A tibble with 312 rows and 8 variables 9 | } 10 | \usage{ 11 | data(election_data) 12 | } 13 | \description{ 14 | A dataset containing election results for parliamentary houses from 15 | Australia, Canada, Chile, Germany, Russia, UK, and USA. The variables are as follows: 16 | } 17 | \details{ 18 | \itemize{ 19 | \item year. The year of the election (1990-2025) 20 | \item country. The country the election took place within (Australia, Canada, Chile, Germany, Russia, UK, and USA) 21 | \item house. The parliamentary house of the election 22 | \item party_long. The full name of a party which had elected representatives 23 | \item party_short. The abbreviated name of a party which had elected representatives 24 | \item seats. The number of seats won by each party 25 | \item government. Whether or not that party was a part of the government following the election (1, 0) 26 | \item colour. A hex code indicating the colours of each party 27 | } 28 | } 29 | \keyword{datasets} 30 | -------------------------------------------------------------------------------- /man/geom_parliament_bar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/geom_parliament_bar.R 3 | \name{geom_parliament_bar} 4 | \alias{geom_parliament_bar} 5 | \title{Add a bar showing proportion of seats by party in parliament} 6 | \usage{ 7 | geom_parliament_bar(colour = colour, party = party, label = TRUE) 8 | } 9 | \arguments{ 10 | \item{colour}{The colours associated with each political party.} 11 | 12 | \item{party}{The party name variable in your data frame.} 13 | 14 | \item{label}{If label = TRUE, print the percentage above the bar.} 15 | } 16 | \description{ 17 | Add a bar showing proportion of seats by party in parliament 18 | } 19 | \examples{ 20 | data <- election_data[election_data$country == "USA" & 21 | election_data$house == "Representatives" & 22 | election_data$year == "2016", ] 23 | usa_data <- parliament_data( 24 | election_data = data, 25 | type = "semicircle", 26 | party_seats = data$seats, 27 | parl_rows = 8 28 | ) 29 | ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 30 | geom_parliament_seats() + 31 | geom_parliament_bar(colour, party_long) + 32 | ggplot2::scale_colour_manual(values = usa_data$colour, limits = usa_data$party_long) + 33 | theme_ggparliament() 34 | } 35 | \author{ 36 | Zoe Meers 37 | } 38 | -------------------------------------------------------------------------------- /man/theme_ggparliament.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/theme_ggparliament.R 3 | \name{theme_ggparliament} 4 | \alias{theme_ggparliament} 5 | \title{A theme for ggparliament} 6 | \usage{ 7 | theme_ggparliament(legend, background_colour, border) 8 | } 9 | \arguments{ 10 | \item{legend}{If legend = `TRUE`, add legend to plot. Defaults to `TRUE`.} 11 | 12 | \item{background_colour}{If background colour = `TRUE`, fill panel with a grey background. Defaults to `FALSE`.} 13 | 14 | \item{border}{If `TRUE` add panel border. Defaults to `FALSE`.} 15 | } 16 | \description{ 17 | Calls the ggparliament theme. A reconstructed opinionated theme_void() ggplot2 theme. 18 | } 19 | \examples{ 20 | data <- election_data[ 21 | election_data$country == "USA" & 22 | election_data$house == "Representatives" & 23 | election_data$year == "2016", 24 | ] 25 | usa_data <- parliament_data( 26 | election_data = data, 27 | type = "semicircle", 28 | party_seats = data$seats, 29 | parl_rows = 8 30 | ) 31 | ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 32 | geom_parliament_seats() + 33 | geom_highlight_government(government == 1) + 34 | theme_ggparliament(legend = TRUE, background_colour = TRUE, border = TRUE) 35 | } 36 | \author{ 37 | Zoe Meers 38 | } 39 | -------------------------------------------------------------------------------- /man/draw_totalseats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/draw_totalseats.R 3 | \name{draw_totalseats} 4 | \alias{draw_totalseats} 5 | \title{Draw total number of seats in the middle of the parliament} 6 | \usage{ 7 | draw_totalseats( 8 | n = NULL, 9 | size = 12, 10 | colour = "black", 11 | type = c("horseshoe", "semicircle", "opposing_benches", "circle", "classroom") 12 | ) 13 | } 14 | \arguments{ 15 | \item{n}{The number of total seats in the legislature.} 16 | 17 | \item{size}{Size of font} 18 | 19 | \item{colour}{colour of label} 20 | 21 | \item{type}{Type of parliament (horseshoe, semicircle, circle, opposing benches, classroom)} 22 | } 23 | \description{ 24 | Draw total number of seats in the middle of the parliament 25 | } 26 | \examples{ 27 | data <- election_data[ 28 | election_data$country == "USA" & 29 | election_data$house == "Representatives" & 30 | election_data$year == "2016", 31 | ] 32 | usa_data <- parliament_data( 33 | election_data = data, 34 | type = "semicircle", 35 | party_seats = data$seats, 36 | parl_rows = 8 37 | ) 38 | ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 39 | geom_parliament_seats() + 40 | draw_totalseats(n = 435, type = "semicircle") + 41 | theme_ggparliament() 42 | } 43 | \author{ 44 | Zoe Meers 45 | } 46 | -------------------------------------------------------------------------------- /man/geom_highlight_government.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/geom_highlight_government.R 3 | \name{geom_highlight_government} 4 | \alias{geom_highlight_government} 5 | \title{Highlight governments or parties in control of the legislature by encircling the points.} 6 | \source{ 7 | https://yutani.rbind.io/post/2017-11-07-ggplot-add/ 8 | } 9 | \usage{ 10 | geom_highlight_government(expr, colour, size, shape, stroke) 11 | } 12 | \arguments{ 13 | \item{expr}{Expr refers to the observation that you wish to highlight.} 14 | 15 | \item{colour}{Colour of the highlight} 16 | 17 | \item{size}{Size of highlighter} 18 | 19 | \item{shape}{Shape of highlight} 20 | 21 | \item{stroke}{Size of stroke shape} 22 | } 23 | \description{ 24 | Highlight governments or parties in control of the legislature by encircling the points. 25 | } 26 | \examples{ 27 | data <- election_data[ 28 | election_data$country == "USA" & 29 | election_data$house == "Representatives" & 30 | election_data$year == "2016", 31 | ] 32 | usa_data <- parliament_data( 33 | election_data = data, 34 | type = "semicircle", 35 | party_seats = data$seats, 36 | parl_rows = 8 37 | ) 38 | ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 39 | geom_parliament_seats() + 40 | geom_highlight_government(government == 1) + 41 | theme_ggparliament() 42 | } 43 | \author{ 44 | Zoe Meers 45 | } 46 | -------------------------------------------------------------------------------- /man/parliament_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parliament_data.R 3 | \name{parliament_data} 4 | \alias{parliament_data} 5 | \title{A function that prepares data for parliamentary plots} 6 | \usage{ 7 | parliament_data( 8 | election_data = NULL, 9 | parl_rows = NULL, 10 | party_seats = election_data$seats, 11 | group = NULL, 12 | plot_order = NULL, 13 | type = c("horseshoe", "semicircle", "thirdcircle", "third_circle", "circle", 14 | "classroom", "opposing_benches") 15 | ) 16 | } 17 | \arguments{ 18 | \item{election_data}{aggregate election results} 19 | 20 | \item{parl_rows}{number of rows in parliament} 21 | 22 | \item{party_seats}{seats per party} 23 | 24 | \item{group}{grouping variable for separate chunks. e.g. opposing benches in UK parliament} 25 | 26 | \item{plot_order}{plot the data in a specified order} 27 | 28 | \item{type}{type of parliament (horseshoe, semicircle, circle, classroom, opposing benches)} 29 | } 30 | \description{ 31 | A function that prepares data for parliamentary plots 32 | } 33 | \examples{ 34 | data <- election_data[ 35 | election_data$country == "USA" & 36 | election_data$house == "Representatives" & 37 | election_data$year == "2016", 38 | ] 39 | usa_data <- parliament_data( 40 | election_data = data, 41 | type = "semicircle", 42 | party_seats = data$seats, 43 | parl_rows = 8 44 | ) 45 | } 46 | \author{ 47 | Zoe Meers, Rob Hickman 48 | } 49 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: ggparliament 2 | Type: Package 3 | Title: Parliament Plots 4 | Description: Simple parliament plots using 'ggplot2'. Visualize election results as points in the architectural layout of the legislative chamber. 5 | Depends: R (>= 3.5.0) 6 | License: MIT + file LICENSE 7 | Version: 3.1.7 8 | Date: 2025-07-14 9 | Authors@R: c(person("Robert", "Hickman", role = c("aut"), email = "robwhickman@gmail.com"), person("Zoe", "Meers", role = c("aut", "cre"), email = "zoe.meers@gmail.com"), person("Thomas J.", "Leeper",role = c("aut"), email = "thosjleeper@gmail.com", comment = c(ORCID = "0000-0003-4097-6326"))) 10 | URL: https://github.com/zmeers/ggparliament 11 | BugReports: https://github.com/zmeers/ggparliament/issues 12 | LazyData: true 13 | Imports: 14 | ggplot2, 15 | dplyr, 16 | rlang 17 | Suggests: 18 | tidyr, 19 | magrittr, 20 | knitr, 21 | testthat, 22 | rmarkdown, 23 | purrr, 24 | ggrepel, 25 | scales, 26 | markdown 27 | VignetteBuilder: knitr 28 | RoxygenNote: 7.3.2 29 | Encoding: UTF-8 30 | Collate: 31 | 'ggparliament_package.R' 32 | 'data.R' 33 | 'draw_majoritythreshold.R' 34 | 'helper_funcs.R' 35 | 'parliament_data.R' 36 | 'draw_partylabels.R' 37 | 'draw_totalseats.R' 38 | 'geom_parliament_seats.R' 39 | 'geom_emphasize_parliamentarians.R' 40 | 'geom_parliament_bar.R' 41 | 'geom_highlight_government.R' 42 | 'geom_overhang_seats.R' 43 | 'theme_ggparliament.R' 44 | -------------------------------------------------------------------------------- /man/geom_overhang_seats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/geom_overhang_seats.R 3 | \name{geom_overhang_seats} 4 | \alias{geom_overhang_seats} 5 | \title{Draw overhang seats in mixed-member proportional (MMP) electoral systems} 6 | \usage{ 7 | geom_overhang_seats(expr) 8 | } 9 | \arguments{ 10 | \item{expr}{Expr refers to the designated overhang seats.} 11 | } 12 | \description{ 13 | Draw overhang seats in mixed-member proportional (MMP) electoral systems 14 | } 15 | \examples{ 16 | germany <- data.frame( 17 | year = 2013, 18 | seats = c(64, 63, 311, 193), 19 | government = c(0, 0, 1, 1), 20 | colour = c("#BE3075", "#64A12D", "#000000", "#EB001F"), 21 | party = c( 22 | "The Left", 23 | "Alliance 90/The Greens", 24 | "Christian Democratic Union", 25 | "Social Democratic Party" 26 | ) 27 | ) 28 | german_data <- parliament_data( 29 | election_data = germany, 30 | parl_rows = 11, 31 | party_seats = germany$seats, 32 | type = "semicircle" 33 | ) 34 | german_data$overhang_seats <- rep( 35 | c(1, 0, 1, 0, 1, 0, 1, 0), 36 | c(16, 295, 11, 182, 3, 61, 3, 60) 37 | ) 38 | ggplot2::ggplot(german_data, ggplot2::aes(x, y, colour = party)) + 39 | geom_parliament_seats() + 40 | geom_overhang_seats(overhang_seats == 1) + 41 | theme_ggparliament() + 42 | ggplot2::scale_colour_manual( 43 | values = as.character(german_data$colour), 44 | limits = as.character(german_data$party) 45 | ) 46 | } 47 | \author{ 48 | Zoe Meers 49 | } 50 | -------------------------------------------------------------------------------- /man/draw_majoritythreshold.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/draw_majoritythreshold.R 3 | \name{draw_majoritythreshold} 4 | \alias{draw_majoritythreshold} 5 | \title{Draw majority threshold} 6 | \usage{ 7 | draw_majoritythreshold( 8 | n = NULL, 9 | label = TRUE, 10 | type = c("horseshoe", "semicircle", "opposing_benches"), 11 | linecolour = "black", 12 | linesize = 1, 13 | linetype = 2, 14 | linealpha = 1 15 | ) 16 | } 17 | \arguments{ 18 | \item{n}{The number of seats required for a majority} 19 | 20 | \item{label}{A logical variable for labelling majority threshold. Defaults to TRUE.} 21 | 22 | \item{type}{Type of parliament (horseshoe, semicircle,opposing benches)} 23 | 24 | \item{linecolour}{The colour of the majority line. Defaults to gray.} 25 | 26 | \item{linesize}{The size of the line. Defaults to 1.} 27 | 28 | \item{linetype}{The style of the line. Defaults to 2, or a dashed line.} 29 | 30 | \item{linealpha}{Set the transparency of the line. Defaults to 1.} 31 | } 32 | \description{ 33 | Draw majority threshold 34 | } 35 | \examples{ 36 | data <- election_data[ 37 | election_data$country == "USA" & 38 | election_data$house == "Representatives" & 39 | election_data$year == "2016", 40 | ] 41 | usa_data <- parliament_data( 42 | election_data = data, 43 | type = "semicircle", 44 | party_seats = data$seats, 45 | parl_rows = 8 46 | ) 47 | ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 48 | geom_parliament_seats() + 49 | draw_majoritythreshold( 50 | n = 218, 51 | label = TRUE, 52 | type = "semicircle" 53 | ) + 54 | theme_ggparliament() 55 | } 56 | \author{ 57 | Zoe Meers 58 | } 59 | -------------------------------------------------------------------------------- /man/geom_emphasize_parliamentarians.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/geom_emphasize_parliamentarians.R 3 | \name{geom_emphasize_parliamentarians} 4 | \alias{geom_emphasize_parliamentarians} 5 | \title{Emphasize certain parliamentarians (for example, female members of parliament) by increasing transparency on the remaining observations.} 6 | \usage{ 7 | geom_emphasize_parliamentarians(expr, size, shape, stroke) 8 | } 9 | \arguments{ 10 | \item{expr}{The observation that you wish to emphasize} 11 | 12 | \item{size}{The size of the point} 13 | 14 | \item{shape}{The shape of the legislature seat (defaults to circle)} 15 | 16 | \item{stroke}{The size of the stroke} 17 | } 18 | \description{ 19 | Emphasize certain parliamentarians (for example, female members of parliament) by increasing transparency on the remaining observations. 20 | } 21 | \examples{ 22 | data <- election_data[ 23 | election_data$country == "USA" & 24 | election_data$house == "Representatives" & 25 | election_data$year == "2016", 26 | ] 27 | usa_data <- parliament_data( 28 | election_data = data, 29 | type = "semicircle", 30 | party_seats = data$seats, 31 | parl_rows = 8 32 | ) 33 | 34 | women_in_congress <- c(1, 0, 0, 1) 35 | number_of_women <- c(23, 218, 133, 61) 36 | 37 | usa_data$women <- rep(women_in_congress, number_of_women) 38 | 39 | ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 40 | geom_parliament_seats() + 41 | geom_emphasize_parliamentarians(women == 1) + 42 | theme_ggparliament(legend = FALSE) + 43 | ggplot2::scale_colour_manual(values = usa_data$colour, limits = usa_data$party_long) + 44 | ggplot2::labs(title = "Women in Congress") 45 | } 46 | \author{ 47 | Zoe Meers 48 | } 49 | -------------------------------------------------------------------------------- /man/geom_parliament_seats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/geom_parliament_seats.R 3 | \name{geom_parliament_seats} 4 | \alias{geom_parliament_seats} 5 | \title{Parliament seats 6 | The parliament seats geom is used for plotting data from parliament_data()} 7 | \usage{ 8 | geom_parliament_seats( 9 | mapping = NULL, 10 | data = NULL, 11 | stat = "identity", 12 | position = "identity", 13 | na.rm = FALSE, 14 | size = 3.5, 15 | show.legend = NA, 16 | inherit.aes = TRUE 17 | ) 18 | } 19 | \arguments{ 20 | \item{mapping}{Mapping the aesthetics (the x and y coordinates, 21 | as well as the colour of each political party).} 22 | 23 | \item{data}{The parliament_data data frame.} 24 | 25 | \item{stat}{"identity"} 26 | 27 | \item{position}{"identity"} 28 | 29 | \item{na.rm}{If `FALSE`, the default, missing values are 30 | removed with a warning. 31 | If `TRUE`, missing values are silently removed.} 32 | 33 | \item{size}{Size of the point} 34 | 35 | \item{show.legend}{If `TRUE`, print legend. 36 | If `FALSE` do not print legend.} 37 | 38 | \item{inherit.aes}{Inherit aes from other ggplot2 functions.} 39 | } 40 | \description{ 41 | Parliament seats 42 | The parliament seats geom is used for plotting data from parliament_data() 43 | } 44 | \examples{ 45 | data <- election_data[ 46 | election_data$country == "USA" & 47 | election_data$house == "Representatives" & 48 | election_data$year == "2016", 49 | ] 50 | usa_data <- parliament_data( 51 | election_data = data, 52 | type = "semicircle", party_seats = data$seats, 53 | parl_rows = 8 54 | ) 55 | ggplot2::ggplot(usa_data, ggplot2::aes(x = x, y = y, colour = party_long)) + 56 | geom_parliament_seats() + 57 | theme_ggparliament() 58 | } 59 | \author{ 60 | Zoe Meers 61 | } 62 | -------------------------------------------------------------------------------- /man/draw_partylabels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/draw_partylabels.R 3 | \name{draw_partylabels} 4 | \alias{draw_partylabels} 5 | \title{Draw labels for political parties and seats per party} 6 | \usage{ 7 | draw_partylabels( 8 | type = c("semicircle", "horseshoe"), 9 | names = TRUE, 10 | seats = TRUE, 11 | party_names = party_names, 12 | party_colours = party_colours, 13 | party_seats = party_seats 14 | ) 15 | } 16 | \arguments{ 17 | \item{type}{Define type. Currently only supports semicircle and horseshoe style parliaments.} 18 | 19 | \item{names}{If TRUE, finds party names from data. Defaults to TRUE.} 20 | 21 | \item{seats}{If TRUE, finds party seats from data. Defaults to TRUE.} 22 | 23 | \item{party_names}{A column containing party names.} 24 | 25 | \item{party_colours}{A column containing party colours.} 26 | 27 | \item{party_seats}{A column containing party seats.} 28 | } 29 | \description{ 30 | Draw labels for political parties and seats per party 31 | } 32 | \examples{ 33 | data <- election_data[ 34 | election_data$country == "USA" & 35 | election_data$house == "Representatives" & 36 | election_data$year == "2016", 37 | ] 38 | usa_data <- parliament_data( 39 | election_data = data, 40 | type = "semicircle", 41 | party_seats = data$seats, 42 | parl_rows = 8 43 | ) 44 | ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 45 | geom_parliament_seats() + 46 | draw_partylabels( 47 | type = "semicircle", 48 | party_names = party_long, 49 | party_seats = seats, 50 | party_colours = colour 51 | ) + 52 | ggplot2::scale_colour_manual( 53 | values = usa_data$colour, 54 | limits = usa_data$party_long 55 | ) + 56 | theme_ggparliament() 57 | } 58 | \author{ 59 | Zoe Meers 60 | } 61 | -------------------------------------------------------------------------------- /R/geom_highlight_government.R: -------------------------------------------------------------------------------- 1 | #' Highlight governments or parties in control of the legislature by encircling the points. 2 | #' @param expr Expr refers to the observation that you wish to highlight. 3 | #' @param colour Colour of the highlight 4 | #' @param size Size of highlighter 5 | #' @param shape Shape of highlight 6 | #' @param stroke Size of stroke shape 7 | #' @examples 8 | #' data <- election_data[ 9 | #' election_data$country == "USA" & 10 | #' election_data$house == "Representatives" & 11 | #' election_data$year == "2016", 12 | #' ] 13 | #' usa_data <- parliament_data( 14 | #' election_data = data, 15 | #' type = "semicircle", 16 | #' party_seats = data$seats, 17 | #' parl_rows = 8 18 | #' ) 19 | #' ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 20 | #' geom_parliament_seats() + 21 | #' geom_highlight_government(government == 1) + 22 | #' theme_ggparliament() 23 | #' @usage geom_highlight_government(expr, colour, size, shape, stroke) 24 | #' @author Zoe Meers 25 | #' @source https://yutani.rbind.io/post/2017-11-07-ggplot-add/ 26 | #' @export 27 | #' @importFrom ggplot2 ggplot_add 28 | 29 | geom_highlight_government <- function(expr, colour = "black", size = 3, shape = 19, stroke = 1.8) { 30 | structure(list( 31 | expr = rlang::enquo(expr), 32 | colour = colour, 33 | size = size, 34 | shape = shape, 35 | stroke = stroke 36 | ), class = "highlight") 37 | } 38 | 39 | 40 | #' @export 41 | ggplot_add.highlight <- function(object, plot, object_name) { 42 | new_data <- dplyr::filter(plot$data, !!object$expr) 43 | new_layer <- ggplot2::geom_point( 44 | data = new_data, 45 | mapping = plot$mapping, 46 | colour = object$colour, 47 | show.legend = FALSE, 48 | size = object$size, 49 | stroke = object$stroke, 50 | shape = object$shape 51 | ) 52 | plot$layers <- append(new_layer, plot$layers) 53 | plot 54 | } 55 | -------------------------------------------------------------------------------- /R/geom_overhang_seats.R: -------------------------------------------------------------------------------- 1 | 2 | #' Draw overhang seats in mixed-member proportional (MMP) electoral systems 3 | #' @param expr Expr refers to the designated overhang seats. 4 | #' @examples 5 | #' germany <- data.frame( 6 | #' year = 2013, 7 | #' seats = c(64, 63, 311, 193), 8 | #' government = c(0, 0, 1, 1), 9 | #' colour = c("#BE3075", "#64A12D", "#000000", "#EB001F"), 10 | #' party = c( 11 | #' "The Left", 12 | #' "Alliance 90/The Greens", 13 | #' "Christian Democratic Union", 14 | #' "Social Democratic Party" 15 | #' ) 16 | #' ) 17 | #' german_data <- parliament_data( 18 | #' election_data = germany, 19 | #' parl_rows = 11, 20 | #' party_seats = germany$seats, 21 | #' type = "semicircle" 22 | #' ) 23 | #' german_data$overhang_seats <- rep( 24 | #' c(1, 0, 1, 0, 1, 0, 1, 0), 25 | #' c(16, 295, 11, 182, 3, 61, 3, 60) 26 | #' ) 27 | #' ggplot2::ggplot(german_data, ggplot2::aes(x, y, colour = party)) + 28 | #' geom_parliament_seats() + 29 | #' geom_overhang_seats(overhang_seats == 1) + 30 | #' theme_ggparliament() + 31 | #' ggplot2::scale_colour_manual( 32 | #' values = as.character(german_data$colour), 33 | #' limits = as.character(german_data$party) 34 | #' ) 35 | #' @usage 36 | #' geom_overhang_seats(expr) 37 | #' @author Zoe Meers 38 | #' @export 39 | #' @importFrom ggplot2 ggplot_add 40 | 41 | 42 | geom_overhang_seats <- function(expr) { 43 | structure(list(expr = rlang::enquo(expr)), class = "hangingseats") 44 | } 45 | 46 | #' @export 47 | ggplot_add.hangingseats <- function(object, plot, object_name) { 48 | new_data <- dplyr::filter(plot$data, !!object$expr) 49 | new_layer <- ggplot2::geom_point( 50 | data = new_data, 51 | mapping = plot$mapping, 52 | fill = "white", 53 | show.legend = FALSE, 54 | shape = 21, 55 | size = 2, 56 | stroke = 0.5 57 | ) 58 | plot$layers <- append(plot$layers, new_layer) 59 | plot 60 | } 61 | -------------------------------------------------------------------------------- /R/helper_funcs.R: -------------------------------------------------------------------------------- 1 | #' A function that calculates the coordinates of parliamentary seats in incomplete circular parliaments 2 | #' E.g. The US (semicircle) and Australian (horseshoe) shaped parliaments 3 | #' @param N the total of number of seats 4 | #' @param M the number of rows in parliament 5 | #' @param limits the limits to seq the radii between- controls the 'shape' of the parliament 6 | #' @param segment the percentage of a full circle for the final plot- defaults to 0.5 (a semicircle) 7 | #' @author 8 | #' Zoe Meers, Rob Hickman 9 | 10 | calc_coordinates <- function(N, M, limits, segment = 0.5) { 11 | # controls the spread of the seats 12 | # tigher limits = more 'pinched' circle 13 | radii <- seq(limits[1], limits[2], len = M) 14 | 15 | counts <- numeric(M) 16 | 17 | pts <- do.call( 18 | rbind, 19 | lapply(1:M, function(i) { 20 | # find how many seats for this parl_row 21 | counts[i] <<- round(N * radii[i] / sum(radii[i:M])) 22 | # For a hemicycle, seq from 0-180degrees for the row for the cartesian position 23 | # For a narrower cycle (where segment < 0.5), calculate the offset (theta_narrow) 24 | # in radians from each side 25 | theta_narrow <- (0.5 - segment) * pi 26 | # theta_left is the left-hand start of the arc 27 | theta_left <- theta_narrow 28 | # theta_right is the right-hand end of the arc 29 | theta_right <- pi - theta_narrow 30 | theta <- seq( theta_left, theta_right, 31 | len = counts[i]) 32 | # subtract the seats already plotted from N 33 | # N becomes 'seats left to calculate' 34 | N <<- N - counts[i] 35 | 36 | # wrap this into a df 37 | # calculate x and y coords 38 | data.frame( 39 | x = radii[i] * cos(theta), 40 | y = radii[i] * sin(theta), 41 | row = i, 42 | theta = theta 43 | ) 44 | }) 45 | ) 46 | 47 | # arrange by angle then row 48 | # assume 'first' party starts in bottom left 49 | pts <- pts[order(-pts$theta, -pts$row), ] 50 | pts 51 | } 52 | -------------------------------------------------------------------------------- /R/theme_ggparliament.R: -------------------------------------------------------------------------------- 1 | #' A theme for ggparliament 2 | #' @description 3 | #' Calls the ggparliament theme. A reconstructed opinionated theme_void() ggplot2 theme. 4 | #' @usage 5 | #' theme_ggparliament(legend, background_colour, border) 6 | #' @param legend If legend = `TRUE`, add legend to plot. Defaults to `TRUE`. 7 | #' @param background_colour If background colour = `TRUE`, fill panel with a grey background. Defaults to `FALSE`. 8 | #' @param border If `TRUE` add panel border. Defaults to `FALSE`. 9 | #' @examples 10 | #' data <- election_data[ 11 | #' election_data$country == "USA" & 12 | #' election_data$house == "Representatives" & 13 | #' election_data$year == "2016", 14 | #' ] 15 | #' usa_data <- parliament_data( 16 | #' election_data = data, 17 | #' type = "semicircle", 18 | #' party_seats = data$seats, 19 | #' parl_rows = 8 20 | #' ) 21 | #' ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 22 | #' geom_parliament_seats() + 23 | #' geom_highlight_government(government == 1) + 24 | #' theme_ggparliament(legend = TRUE, background_colour = TRUE, border = TRUE) 25 | #' @author Zoe Meers 26 | #' @export 27 | 28 | theme_ggparliament <- function(legend = TRUE, 29 | background_colour = FALSE, 30 | border = FALSE) { 31 | basic_theme <- ggplot2::theme_void() 32 | 33 | 34 | if (legend == TRUE) { 35 | basic_theme <- basic_theme 36 | } else { 37 | basic_theme <- basic_theme + ggplot2::theme(legend.position = "none") 38 | } 39 | 40 | 41 | 42 | if (!background_colour) { 43 | basic_theme <- basic_theme 44 | } else { 45 | basic_theme <- basic_theme + ggplot2::theme(panel.background = ggplot2::element_rect(fill = "#F5F5F5", colour = NA)) # white smoke fill 46 | } 47 | 48 | 49 | if (!border) { 50 | basic_theme <- basic_theme 51 | } else { 52 | basic_theme <- basic_theme + ggplot2::theme(panel.border = ggplot2::element_rect(colour = "#F5F5F5", fill = NA)) # white smoke colour 53 | } 54 | 55 | basic_theme 56 | } 57 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /R/geom_emphasize_parliamentarians.R: -------------------------------------------------------------------------------- 1 | #' Emphasize certain parliamentarians (for example, female members of parliament) by increasing transparency on the remaining observations. 2 | #' @param expr The observation that you wish to emphasize 3 | #' @param size The size of the point 4 | #' @param shape The shape of the legislature seat (defaults to circle) 5 | #' @param stroke The size of the stroke 6 | #' @examples 7 | #' data <- election_data[ 8 | #' election_data$country == "USA" & 9 | #' election_data$house == "Representatives" & 10 | #' election_data$year == "2016", 11 | #' ] 12 | #' usa_data <- parliament_data( 13 | #' election_data = data, 14 | #' type = "semicircle", 15 | #' party_seats = data$seats, 16 | #' parl_rows = 8 17 | #' ) 18 | #' 19 | #' women_in_congress <- c(1, 0, 0, 1) 20 | #' number_of_women <- c(23, 218, 133, 61) 21 | #' 22 | #' usa_data$women <- rep(women_in_congress, number_of_women) 23 | #' 24 | #' ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 25 | #' geom_parliament_seats() + 26 | #' geom_emphasize_parliamentarians(women == 1) + 27 | #' theme_ggparliament(legend = FALSE) + 28 | #' ggplot2::scale_colour_manual(values = usa_data$colour, limits = usa_data$party_long) + 29 | #' ggplot2::labs(title = "Women in Congress") 30 | #' @usage 31 | #' geom_emphasize_parliamentarians(expr, size, shape, stroke) 32 | #' @author Zoe Meers 33 | #' @export 34 | #' @importFrom ggplot2 ggplot_add 35 | 36 | geom_emphasize_parliamentarians <- function(expr, size = 3, shape = 19, stroke = 1.8) { 37 | structure(list( 38 | expr = rlang::enquo(expr), 39 | size = size, 40 | shape = shape, 41 | stroke = stroke 42 | ), 43 | class = "emphMPs" 44 | ) 45 | } 46 | 47 | 48 | #' @export 49 | ggplot_add.emphMPs <- function(object, plot, object_name) { 50 | new_data <- dplyr::filter(plot$data, !(!!object$expr)) 51 | new_layer <- ggplot2::geom_point( 52 | data = new_data, 53 | mapping = plot$mapping, 54 | colour = alpha(0.6), 55 | alpha = 0.6, 56 | size = object$size, 57 | stroke = object$stroke, 58 | shape = object$shape 59 | ) 60 | plot$layers <- append(plot$layers, new_layer) 61 | plot 62 | } 63 | -------------------------------------------------------------------------------- /paper/paper.bib: -------------------------------------------------------------------------------- 1 | @Manual{R, 2 | title = {R: A Language and Environment for Statistical Computing}, 3 | author = {{R Core Team}}, 4 | organization = {R Foundation for Statistical Computing}, 5 | address = {Vienna, Austria}, 6 | year = {2018}, 7 | url = {https://www.R-project.org/}, 8 | } 9 | @Manual{tidyverse, 10 | title = {tidyverse: Easily Install and Load the 'Tidyverse'}, 11 | author = {Hadley Wickham}, 12 | year = {2017}, 13 | note = {R package version 1.2.1}, 14 | url = {https://CRAN.R-project.org/package=tidyverse}, 15 | } 16 | 17 | @Article{MatchIt, 18 | title = {{MatchIt}: Nonparametric Preprocessing for Parametric Causal Inference}, 19 | author = {Daniel E. Ho and Kosuke Imai and Gary King and Elizabeth A. Stuart}, 20 | journal = {Journal of Statistical Software}, 21 | year = {2011}, 22 | volume = {42}, 23 | number = {8}, 24 | pages = {1--28}, 25 | doi = {10.18637/jss.v042.i08}, 26 | url = {http://www.jstatsoft.org/v42/i08/}, 27 | } 28 | 29 | @Article{Amelia, 30 | title = {{Amelia II}: A Program for Missing Data}, 31 | author = {James Honaker and Gary King and Matthew Blackwell}, 32 | journal = {Journal of Statistical Software}, 33 | year = {2011}, 34 | volume = {45}, 35 | number = {7}, 36 | pages = {1--47}, 37 | doi = {10.18637/jss.v045.i07}, 38 | url = {http://www.jstatsoft.org/v45/i07/}, 39 | } 40 | 41 | @Manual{margins, 42 | title = {margins: Marginal Effects for Model Objects}, 43 | author = {Thomas J. Leeper}, 44 | year = {2018}, 45 | note = {R package version 0.3.23}, 46 | } 47 | 48 | @Manual{pscl, 49 | title = {{pscl}: Classes and Methods for {R} Developed in the Political Science Computational Laboratory}, 50 | author = {Simon Jackman}, 51 | organization = {United States Studies Centre, University of Sydney}, 52 | address = {Sydney, New South Wales, Australia}, 53 | year = {2017}, 54 | note = {R package version 1.5.2}, 55 | url = {https://github.com/atahk/pscl/}, 56 | } 57 | 58 | @Book{ggplot2, 59 | author = {Hadley Wickham}, 60 | title = {ggplot2: Elegant Graphics for Data Analysis}, 61 | publisher = {Springer-Verlag New York}, 62 | year = {2016}, 63 | isbn = {978-3-319-24277-4}, 64 | url = {http://ggplot2.org}, 65 | } -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /R/geom_parliament_seats.R: -------------------------------------------------------------------------------- 1 | #' Parliament seats 2 | #' The parliament seats geom is used for plotting data from parliament_data() 3 | #' @param mapping Mapping the aesthetics (the x and y coordinates, 4 | #' as well as the colour of each political party). 5 | #' @param data The parliament_data data frame. 6 | #' @param stat "identity" 7 | #' @param size Size of the point 8 | #' @param position "identity" 9 | #' @param na.rm If `FALSE`, the default, missing values are 10 | #' removed with a warning. 11 | #' If `TRUE`, missing values are silently removed. 12 | #' @param show.legend If `TRUE`, print legend. 13 | #' If `FALSE` do not print legend. 14 | #' @param inherit.aes Inherit aes from other ggplot2 functions. 15 | #' @examples 16 | #' data <- election_data[ 17 | #' election_data$country == "USA" & 18 | #' election_data$house == "Representatives" & 19 | #' election_data$year == "2016", 20 | #' ] 21 | #' usa_data <- parliament_data( 22 | #' election_data = data, 23 | #' type = "semicircle", party_seats = data$seats, 24 | #' parl_rows = 8 25 | #' ) 26 | #' ggplot2::ggplot(usa_data, ggplot2::aes(x = x, y = y, colour = party_long)) + 27 | #' geom_parliament_seats() + 28 | #' theme_ggparliament() 29 | #' @author Zoe Meers 30 | #' @export 31 | geom_parliament_seats <- function(mapping = NULL, 32 | data = NULL, 33 | stat = "identity", 34 | position = "identity", 35 | na.rm = FALSE, 36 | size = 3.5, 37 | show.legend = NA, 38 | inherit.aes = TRUE) { 39 | layer( 40 | data = data, 41 | mapping = mapping, 42 | stat = stat, 43 | geom = GeomPoint, 44 | position = position, 45 | show.legend = show.legend, 46 | inherit.aes = inherit.aes, 47 | params = list( 48 | na.rm = na.rm, 49 | size = size 50 | ) 51 | ) 52 | } 53 | 54 | #' ggplot2-ggproto 55 | #' @rdname ggplot2-ggproto 56 | #' @name GeomParliamentSeats 57 | #' @format NULL 58 | #' @usage NULL 59 | #' @export 60 | GeomParliamentSeats <- ggplot2::ggproto("GeomParliamentSeats", ggplot2::Geom, 61 | required_aes = c("x", "y", "colour"), 62 | non_missing_aes = c("shape", "size"), 63 | default_aes = ggplot2::aes( 64 | shape = 19, 65 | colour = "black", 66 | size = 3.5, 67 | fill = NA, 68 | alpha = NA, 69 | stroke = 1 70 | ), 71 | 72 | draw_panel = function(data, panel_params, coord, na.rm = FALSE) { 73 | coords <- coord$transform(data, panel_params) 74 | ggplot2:::ggname( 75 | "geom_parliament_seats", 76 | grid::pointsGrob( 77 | coords$x, coords$y, 78 | pch = coords$shape, 79 | gp = grid::gpar( 80 | col = alpha(coords$colour, coords$alpha), 81 | fill = alpha(coords$fill, coords$alpha), 82 | fontsize = coords$size * ggplot2::.pt + coords$stroke * .stroke, 83 | lwd = coords$stroke * .stroke 84 | ) 85 | ) 86 | ) 87 | }, 88 | 89 | draw_key = ggplot2::draw_key_point 90 | ) 91 | -------------------------------------------------------------------------------- /R/geom_parliament_bar.R: -------------------------------------------------------------------------------- 1 | #' Add a bar showing proportion of seats by party in parliament 2 | #' @param party The party name variable in your data frame. 3 | #' @param colour The colours associated with each political party. 4 | #' @param label If label = TRUE, print the percentage above the bar. 5 | #' @examples 6 | #' data <- election_data[election_data$country == "USA" & 7 | #' election_data$house == "Representatives" & 8 | #' election_data$year == "2016", ] 9 | #' usa_data <- parliament_data( 10 | #' election_data = data, 11 | #' type = "semicircle", 12 | #' party_seats = data$seats, 13 | #' parl_rows = 8 14 | #' ) 15 | #' ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 16 | #' geom_parliament_seats() + 17 | #' geom_parliament_bar(colour, party_long) + 18 | #' ggplot2::scale_colour_manual(values = usa_data$colour, limits = usa_data$party_long) + 19 | #' theme_ggparliament() 20 | #' @author Zoe Meers 21 | #' @export 22 | #' @importFrom ggplot2 ggplot_add 23 | 24 | 25 | geom_parliament_bar <- function(colour = colour, party = party, label = TRUE) { 26 | structure( 27 | list( 28 | colour = rlang::enquo(colour), 29 | label = label, 30 | party = rlang::enquo(party) 31 | ), 32 | class = "parliamentBar" 33 | ) 34 | } 35 | 36 | #' @export 37 | ggplot_add.parliamentBar <- function(object, plot, object_name) { 38 | count <- mutate <- n <- proportion <- proportion1 <- start <- end <- p <- group_no <- label <- NULL 39 | 40 | 41 | y_min <- min(plot$data$y, na.rm = TRUE) 42 | y_max <- max(plot$data$y, na.rm = TRUE) 43 | 44 | x_max <- max(plot$data$x, na.rm = TRUE) 45 | x_min <- min(plot$data$x, na.rm = TRUE) 46 | 47 | difference <- x_max - x_min 48 | 49 | new_dat <- plot$data 50 | new_dat <- dplyr::mutate(new_dat, group_no = match(!!object$party, unique(!!object$party))) 51 | new_dat <- dplyr::count(new_dat, group_no, p = !!object$party, c = !!object$colour) 52 | new_dat$proportion <- new_dat$n / sum(new_dat$n) 53 | new_dat$proportion1 <- new_dat$proportion * difference 54 | new_dat$start <- cumsum(new_dat$proportion1) - x_max 55 | new_dat$end <- c(x_min, (cumsum(new_dat$proportion1)[-nrow(new_dat)] - x_max)) 56 | 57 | 58 | if (object$label == TRUE) { 59 | plot + 60 | geom_rect( 61 | data = new_dat, 62 | ggplot2::aes( 63 | xmin = start, xmax = end, fill = p, 64 | ymin = max(plot$data$y) + 0.2, ymax = max(plot$data$y) + 0.5 65 | ), 66 | inherit.aes = FALSE, show.legend = FALSE 67 | ) + 68 | ggrepel::geom_text_repel(ggplot2::aes(x = rowMeans(cbind(start, end)), y = max(plot$data$y) + 0.55, label = scales::percent(proportion)), vjust = 0, segment.size = 0.02, nudge_y = 0.05, direction = "x", data = new_dat, inherit.aes = FALSE) + 69 | ggplot2::scale_fill_manual(values = new_dat$c, limits = new_dat$p) 70 | } else { 71 | plot + 72 | geom_rect( 73 | data = new_dat, 74 | ggplot2::aes( 75 | xmin = start, xmax = end, fill = p, 76 | ymin = max(plot$data$y) + 0.2, ymax = max(plot$data$y) + 0.5 77 | ), 78 | inherit.aes = FALSE, show.legend = FALSE 79 | ) + 80 | ggplot2::scale_fill_manual(values = new_dat$c, limits = new_dat$p) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /R/draw_totalseats.R: -------------------------------------------------------------------------------- 1 | #' Draw total number of seats in the middle of the parliament 2 | #' @param n The number of total seats in the legislature. 3 | #' @param size Size of font 4 | #' @param colour colour of label 5 | #' @param type Type of parliament (horseshoe, semicircle, circle, opposing benches, classroom) 6 | #' @examples 7 | #' data <- election_data[ 8 | #' election_data$country == "USA" & 9 | #' election_data$house == "Representatives" & 10 | #' election_data$year == "2016", 11 | #' ] 12 | #' usa_data <- parliament_data( 13 | #' election_data = data, 14 | #' type = "semicircle", 15 | #' party_seats = data$seats, 16 | #' parl_rows = 8 17 | #' ) 18 | #' ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 19 | #' geom_parliament_seats() + 20 | #' draw_totalseats(n = 435, type = "semicircle") + 21 | #' theme_ggparliament() 22 | #' @author Zoe Meers 23 | #' @export 24 | #' @importFrom ggplot2 ggplot_add 25 | 26 | 27 | draw_totalseats <- function(n = NULL, 28 | size = 12, 29 | colour = "black", 30 | type = c( 31 | "horseshoe", 32 | "semicircle", 33 | "opposing_benches", 34 | "circle", 35 | "classroom" 36 | )) { 37 | structure( 38 | list( 39 | n = n, 40 | size = size, 41 | type = type, 42 | colour = colour 43 | ), 44 | class = "totalLabels" 45 | ) 46 | } 47 | 48 | #' @export 49 | ggplot_add.totalLabels <- function(object, plot, object_name) { 50 | # n <- rlang::enquo(object$n) 51 | if (object$type == "horseshoe") { 52 | plot + 53 | ggplot2::annotate("text", 54 | x = 0, y = 3, 55 | label = object$n, 56 | fontface = "bold", 57 | size = object$size, 58 | colour = object$colour 59 | ) 60 | } else if (object$type == "classroom") { 61 | plot + 62 | ggplot2::annotate("text", 63 | x = max(plot$data$x) / 2, 64 | y = max(plot$data$y) + 0.2, 65 | label = object$n, 66 | fontface = "bold", 67 | size = object$size, 68 | colour = object$colour 69 | ) 70 | } else if (object$type == "opposing_benches") { 71 | plot + 72 | ggplot2::annotate("text", 73 | x = max(plot$data$x) / 2, 74 | y = max(plot$data$y) / 2, 75 | label = object$n, 76 | fontface = "bold", 77 | size = object$size, 78 | colour = object$colour 79 | ) 80 | } else if (object$type == "semicircle") { 81 | plot + 82 | ggplot2::annotate("text", 83 | x = 0, y = 0.2, 84 | label = object$n, 85 | fontface = "bold", 86 | size = object$size, 87 | colour = object$colour 88 | ) 89 | } else { 90 | plot + 91 | ggplot2::annotate("text", 92 | x = max(plot$data$x) / 2, 93 | y = max(plot$data$y) / 2, 94 | label = object$n, 95 | fontface = "bold", 96 | size = object$size, 97 | colour = object$colour 98 | ) 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /vignettes/f_emphasize_parliamentarians_6.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "How to emphasize parliamentarians" 3 | author: "Zoe Meers" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Emphasize Parliamentarians} 8 | %\VignetteEngine{knitr::knitr} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include=FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | 18 | 19 | library(ggparliament) 20 | library(dplyr) 21 | library(ggplot2) 22 | require(tidyr) 23 | require(magrittr) 24 | 25 | source("../R/parliament_data.R") 26 | source("../R/geom_parliament_seats.R") 27 | source("../R/geom_highlight_government.R") 28 | source("../R/geom_emphasize_parliamentarians.R") 29 | source("../R/helper_funcs.R") 30 | source("../R/draw_majoritythreshold.R") 31 | source("../R/draw_partylabels.R") 32 | source("../R/draw_majoritythreshold.R") 33 | source("../R/draw_totalseats.R") 34 | source("../R/theme_ggparliament.R") 35 | load("../R/sysdata.rda") 36 | 37 | 38 | ``` 39 | 40 | 41 | To emphasize certain parliamentarians, add `geom_emphasize_parliamentarians()` to your `ggplot2` plot, specifying the variable you want to emphasize. This will set the alpha on the remaining seats to 0.6. 42 | 43 | ### Women in the 115th American Congress 44 | ```{r, fig.width = 8, fig.height = 5} 45 | # Take preliminary data as provided in ggparliament 46 | data <- election_data %>% 47 | filter(year == "2016" & country == "USA" & house == "Representatives") 48 | usa_data <- parliament_data(election_data = data, type = "semicircle", party_seats = data$seats, parl_rows = 8) 49 | 50 | # The Center for American Women and Politics provides statistics concerning women in U.S. politics 51 | # See http://www.cawp.rutgers.edu/women-us-congress-2018 for more information. 52 | # We create a binary variable -- women are 1, men are 0 -- for each party. Remember, the plot starts from the left hand side and finishes at the right hand side of the legislature. Given that we want to compare the two parties, it makes sense for them to be roughly parallel. 53 | women_in_congress <- c(1, 0, 0, 1) 54 | # The number of women in US congress - 23 Reps, 61 Dems. The two middle numbers are the remainder (i.e., number of men). 55 | number_of_women <- c(23, 218, 133, 61) 56 | # Use rep and mutate to append the binary female variable to the long data set. 57 | usa_data <- usa_data %>% mutate(women = rep(women_in_congress, number_of_women)) 58 | # Plot the US congress as normal using geom_parliament_seats 59 | ggplot(usa_data, aes(x, y, color=party_long)) + 60 | geom_parliament_seats() + 61 | # emphasize the women in each political party -- this must be specified in order for it to work! 62 | geom_emphasize_parliamentarians(women == 1) + 63 | draw_majoritythreshold(n = 218, label = FALSE, linecolour = "black", type = 'semicircle') + 64 | draw_partylabels(type = 'semicircle', party_seats = seats, party_names = party_short, party_colours = colour) + 65 | theme_void() + 66 | theme(plot.title = element_text(hjust = 0.5), 67 | legend.position = "none") + 68 | scale_colour_manual(values = usa_data$colour, limits = usa_data$party_long) + 69 | annotate(geom = "text", x = 0, y = 0.2, label = "61 Democrats in Congress\n are women. Only 23\nelected Republicans are women.") + 70 | labs(title = "Women in 115th U.S. Congress") 71 | ``` -------------------------------------------------------------------------------- /vignettes/d_highlight-government_4.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "How to highlight government or party in control of the legislature" 3 | author: "Zoe Meers" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Highlight Government} 8 | %\VignetteEngine{knitr::knitr} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include=FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | 18 | 19 | library(ggparliament) 20 | library(dplyr) 21 | library(ggplot2) 22 | require(tidyr) 23 | require(magrittr) 24 | 25 | source("../R/parliament_data.R") 26 | source("../R/geom_parliament_seats.R") 27 | source("../R/geom_highlight_government.R") 28 | source("../R/helper_funcs.R") 29 | source("../R/draw_majoritythreshold.R") 30 | source("../R/draw_partylabels.R") 31 | source("../R/draw_majoritythreshold.R") 32 | source("../R/draw_totalseats.R") 33 | source("../R/theme_ggparliament.R") 34 | load("../R/sysdata.rda") 35 | 36 | 37 | ``` 38 | 39 | ## Highlighting governments or parties in control of legislative chamber 40 | 41 | We can specify whether a party is a part of the government (or otherwise has control of the legislature if they hold a majority of seats) in our visualization by using `geom_highlight_government()`. `geom_highlight_government()` surrounds the circle with an outline. 42 | 43 | ### 115th Congress 44 | 45 | ```{r} 46 | us_congress <- election_data %>% 47 | filter(country == "USA" & 48 | year == 2016 & 49 | house == "Representatives") 50 | head(us_congress) 51 | ``` 52 | 53 | ```{r} 54 | us_congress <- parliament_data(election_data = us_congress, 55 | type = "semicircle", 56 | parl_rows = 10, 57 | party_seats = us_congress$seats) 58 | head(us_congress) 59 | ``` 60 | 61 | ```{r, fig.width=8, fig.height=4} 62 | us <- ggplot(us_congress, aes(x, y, colour = party_short)) + 63 | geom_parliament_seats() + 64 | geom_highlight_government(government == 1) + #specify the variable you want to highlight here! 65 | theme_ggparliament() + 66 | labs(colour = NULL, 67 | title = "United States Congress") + 68 | scale_colour_manual(values = us_congress$colour, 69 | limits = us_congress$party_short) 70 | 71 | us 72 | ``` 73 | 74 | Although the primary purpose is to highlight members of a governing coalition, this function is *not* limited to highlighting governments. If, for example, you wish to highlight the Australian government's front branch, write 75 | ```{r} 76 | australia <- election_data %>% 77 | filter(country == "Australia" & 78 | house == "Representatives" & 79 | year == 2016) 80 | 81 | australia <- parliament_data(election_data = australia, 82 | party_seats = australia$seats, 83 | parl_rows = 4, 84 | type = "horseshoe") 85 | ``` 86 | 87 | ```{r,fig.width=5, fig.height=5} 88 | au <- ggplot(australia, aes(x, y, colour = party_short)) + 89 | geom_parliament_seats() + 90 | geom_highlight_government(row == 1 & government == 1) + # this highlights the front bench. 91 | theme_ggparliament() + 92 | labs(colour = NULL, 93 | title = "Australian Parliament") + 94 | scale_colour_manual(values = australia$colour, 95 | limits = australia$party_short) + 96 | theme(legend.position = 'bottom') 97 | 98 | au 99 | ``` 100 | -------------------------------------------------------------------------------- /vignettes/g_hanging_seats_7.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "How to draw overhang seats in a legislature" 3 | author: "Zoe Meers" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Hanging Seats} 8 | %\VignetteEngine{knitr::knitr} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include=FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | 18 | 19 | library(ggparliament) 20 | library(dplyr) 21 | library(ggplot2) 22 | require(tidyr) 23 | require(magrittr) 24 | 25 | source("../R/parliament_data.R") 26 | source("../R/geom_parliament_seats.R") 27 | source("../R/geom_highlight_government.R") 28 | source("../R/geom_overhang_seats.R") 29 | source("../R/helper_funcs.R") 30 | source("../R/draw_majoritythreshold.R") 31 | source("../R/draw_partylabels.R") 32 | source("../R/draw_majoritythreshold.R") 33 | source("../R/draw_totalseats.R") 34 | source("../R/theme_ggparliament.R") 35 | load("../R/sysdata.rda") 36 | 37 | ``` 38 | 39 | ## What are "overhang seats" and why do they matter? 40 | 41 | Various democratic countries use different processes to elect politicians. A few places use Mixed-member proportional (MMP) representation (Germany, New Zealand, Lesotho and Bolivia). In a MMP electoral system, voters have two votes: one for a representative for their electoral constituency and the other for a nation-wide political party. Seats are filled first by the constituency votes and then by political party. A party wins a certain number of seats based on the total vote percentage (a combination of both constituency votes and party votes). Sometimes a party does not win the number of constituencies needed to fill the total number of seats (i.e., they win 6 seats in total but are only elected to 4 constituencies). The remaining seats are known as **overhang seats**. 42 | 43 | 44 | ## Germany 2013 election 45 | 46 | In 2017, the Bloomberg visual graphics team created [an excellent data visualization](https://www.bloomberg.com/graphics/2017-how-germany-forms-government/) of the German Bundestag prior to the 2017 German election. They represented the overhang seats by adding hollow seats to each party. We have decided to recreate the idea of hollow seats in `ggparliament` with `geom_overhang_seats()`. 47 | 48 | ```{r, fig.width = 9, fig.height = 4} 49 | data <- election_data %>% 50 | filter(country == "Germany" & year == "2013") 51 | # binary variable for overhang seat 52 | overhangseats <- c(1, 0, 1, 0, 1, 0, 1, 0) 53 | # number of overhang seats and remainder for each party 54 | number_overhangseats <- c(3, 61, 3, 60,16, 295, 11, 182) 55 | # expand data 56 | german_data <- parliament_data( 57 | election_data = data, 58 | parl_rows = 11, 59 | party_seats = data$seats, 60 | type = "semicircle" 61 | ) 62 | german_data <- german_data %>% mutate(overhang_seats = rep(overhangseats, number_overhangseats)) 63 | german_parliament <- ggplot(german_data, aes(x, 64 | y, 65 | colour = party_short 66 | )) + 67 | geom_parliament_seats() + 68 | # Hollow the overhang seats as follows: 69 | geom_overhang_seats(overhang_seats == 1) + 70 | labs( 71 | colour = "Party", 72 | title = "German Bundestag - 2013 election", 73 | subtitle = "Overhang seats are hollow." 74 | ) + 75 | theme_void() + 76 | theme( 77 | plot.title = element_text(hjust = 0.5), 78 | plot.subtitle = element_text(hjust = 0.5), 79 | legend.position = "none" 80 | ) + 81 | draw_partylabels(type = "semicircle", 82 | party_colours = colour, 83 | party_names = party_short, 84 | party_seats = seats) + 85 | scale_colour_manual( 86 | values = german_data$colour, 87 | limits = german_data$party_short 88 | ) 89 | german_parliament 90 | ``` 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /404.html 5 | 6 | 7 | /CONTRIBUTING.html 8 | 9 | 10 | /LICENSE-text.html 11 | 12 | 13 | /articles/1_basic-parliament-plots_1.html 14 | 15 | 16 | /articles/2_label-parties_2.html 17 | 18 | 19 | /articles/3_draw-majority-threshold_3.html 20 | 21 | 22 | /articles/4_highlight-government_4.html 23 | 24 | 25 | /articles/5_facet-parliament_5.html 26 | 27 | 28 | /articles/6_emphasize_parliamentarians_6.html 29 | 30 | 31 | /articles/7_hanging_seats_7.html 32 | 33 | 34 | /articles/8_arrange_parliament_8.html 35 | 36 | 37 | /articles/a_basic-parliament-plots_1.html 38 | 39 | 40 | /articles/arrange_parliament_8.html 41 | 42 | 43 | /articles/b_label-parties_2.html 44 | 45 | 46 | /articles/basic-parliament-plots_1.html 47 | 48 | 49 | /articles/c_draw-majority-threshold_3.html 50 | 51 | 52 | /articles/d_highlight-government_4.html 53 | 54 | 55 | /articles/draw-majority-threshold_3.html 56 | 57 | 58 | /articles/e_facet-parliament_5.html 59 | 60 | 61 | /articles/emphasize_parliamentarians_6.html 62 | 63 | 64 | /articles/f_emphasize_parliamentarians_6.html 65 | 66 | 67 | /articles/facet-parliament_5.html 68 | 69 | 70 | /articles/g_hanging_seats_7.html 71 | 72 | 73 | /articles/h_arrange_parliament_8.html 74 | 75 | 76 | /articles/hanging_seats_7.html 77 | 78 | 79 | /articles/highlight-government_4.html 80 | 81 | 82 | /articles/index.html 83 | 84 | 85 | /articles/label-parties_2.html 86 | 87 | 88 | /authors.html 89 | 90 | 91 | /index.html 92 | 93 | 94 | /news/index.html 95 | 96 | 97 | /reference/calc_coordinates.html 98 | 99 | 100 | /reference/draw_majoritythreshold.html 101 | 102 | 103 | /reference/draw_partylabels.html 104 | 105 | 106 | /reference/draw_totalseats.html 107 | 108 | 109 | /reference/election_data.html 110 | 111 | 112 | /reference/geom_emphasize_parliamentarians.html 113 | 114 | 115 | /reference/geom_highlight_government.html 116 | 117 | 118 | /reference/geom_overhang_seats.html 119 | 120 | 121 | /reference/geom_parliament_bar.html 122 | 123 | 124 | /reference/geom_parliament_seats.html 125 | 126 | 127 | /reference/ggparliament-package.html 128 | 129 | 130 | /reference/ggplot2-ggproto.html 131 | 132 | 133 | /reference/index.html 134 | 135 | 136 | /reference/parliament_data.html 137 | 138 | 139 | /reference/theme_ggparliament.html 140 | 141 | 142 | -------------------------------------------------------------------------------- /vignettes/b_label-parties_2.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "How to add party labels and extraneous information to your parliament plot" 3 | author: "Zoe Meers" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Label Parties} 8 | %\VignetteEngine{knitr::knitr} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include=FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | 18 | library(ggparliament) 19 | library(dplyr) 20 | library(ggplot2) 21 | require(tidyr) 22 | require(magrittr) 23 | 24 | source("../R/parliament_data.R") 25 | source("../R/geom_parliament_seats.R") 26 | source("../R/geom_highlight_government.R") 27 | source("../R/helper_funcs.R") 28 | source("../R/draw_majoritythreshold.R") 29 | source("../R/draw_partylabels.R") 30 | source("../R/draw_majoritythreshold.R") 31 | source("../R/draw_totalseats.R") 32 | source("../R/theme_ggparliament.R") 33 | load("../R/sysdata.rda") 34 | 35 | ``` 36 | 37 | `ggparliament` includes two functions for labelling parliament plots. The first, `draw_partylabels()`, plots the abbreviated name of parties and the number of seats allocated to the party. The second function, `draw_totalseats()`, plots the total number of parliamentarians in the center of the graph. 38 | 39 | # Drawing party labels 40 | 41 | ```{r, fig.width=7, fig.height=4} 42 | data <- election_data %>% 43 | filter(year == "2016" & 44 | country == "USA" & 45 | house == "Representatives") 46 | 47 | usa_data <- parliament_data(election_data = data, 48 | type = "semicircle", 49 | party_seats = data$seats, 50 | parl_rows = 8) 51 | 52 | ggplot(usa_data, aes(x, y, color=party_long)) + 53 | geom_parliament_seats() + 54 | labs(colour = NULL) + 55 | draw_partylabels(type = "semicircle", party_names = party_short, 56 | party_seats = seats, party_colours = colour) + 57 | scale_colour_manual(values = usa_data$colour, 58 | limits = usa_data$party_long) + 59 | theme_ggparliament(legend = FALSE) 60 | ``` 61 | 62 | ```{r,fig.width=5, fig.height=4} 63 | australia <- election_data %>% 64 | filter(country == "Australia" & 65 | house == "Representatives" & 66 | year == 2016) 67 | 68 | australia_horseshoe <- parliament_data(election_data = australia, 69 | party_seats = australia$seats, 70 | parl_rows = 4, 71 | type = "horseshoe") 72 | 73 | au <- ggplot(australia_horseshoe, aes(x, y, colour = party_short)) + 74 | geom_parliament_seats() + 75 | theme_ggparliament(legend = FALSE) + 76 | labs(colour = NULL, 77 | title = "Australian Parliament") + 78 | draw_partylabels(type = "horseshoe", party_names = party_short, 79 | party_seats = seats, party_colours = colour) + 80 | scale_colour_manual(values = australia$colour, 81 | limits = australia$party_short) 82 | 83 | au 84 | ``` 85 | 86 | 87 | 88 | # Draw label noting total number of parliamentarians 89 | 90 | ```{r, fig.width=7, fig.height=4} 91 | data <- election_data %>% 92 | filter(year == "2016" & 93 | country == "USA" & 94 | house == "Representatives") 95 | 96 | usa_data <- parliament_data(election_data = data, 97 | type = "semicircle", 98 | party_seats = data$seats, 99 | parl_rows = 8) 100 | 101 | ggplot(usa_data, aes(x, y, color=party_long)) + 102 | geom_parliament_seats() + 103 | labs(colour = NULL) + 104 | draw_totalseats(n = 435, 105 | type = "semicircle") + 106 | scale_colour_manual(values = usa_data$colour, 107 | limits = usa_data$party_long) + 108 | theme_ggparliament(legend = FALSE) 109 | ``` 110 | 111 | 112 | -------------------------------------------------------------------------------- /paper/paper.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'ggparliament: A ggplot2 extension for parliament plots in R' 3 | tags: 4 | - government statistics 5 | - data visualization 6 | - social science 7 | - political science 8 | authors: 9 | - name: Zoe Meers 10 | affiliation: 1 11 | orcid: 0000-0001-8045-6531 12 | - name: Robert Hickman 13 | affiliation: 2 14 | - name: Thomas J. Leeper 15 | affiliation: 3 16 | orcid: 0000-0003-4097-6326 17 | affiliations: 18 | - name: United States Studies Centre, University of Sydney 19 | index: 1 20 | - name: Department of Physiology, Development and Neuroscience, University of Cambridge 21 | index: 2 22 | - name: Department of Methodology, London School of Economics and Political Science 23 | index: 3 24 | date: 12 February 2018 25 | bibliography: paper.bib 26 | --- 27 | 28 | # Summary 29 | 30 | `ggparliament` is a `R` [@R] package for visualizing legislative chambers. It allows for easy visualization of the party composition of a legislative body or for plotting election results using syntax from the `tidyverse`, a set of packages for cleaning, modelling, and visualizing data [@tidyverse]. The package is one of the first `ggplot2` [@ggplot2] extensions for visualizing political data. It is considerably more detailed than most visualization tools for graphing legislatures in that it is designed to handle many different legislatures irrespective of size, number of parties, or characteristics of legislatures. Legislature visualizations are also known as parliament plots or parliament charts. 31 | 32 | Visualizing legislatures can be done in a variety of formats - usually in a JavaScript framework. `ggparliament` seeks to implement the flexibility from JavaScript in `R`. `R` users will find they can use a similar syntax to the popular `ggplot2` package to generate a visualization of a legislative body. In particular, `ggparliament` is a `R` package because `R` is a statistical computing language that many quantitative political scientists use in research. (See `pscl` [@pscl], `Amelia` [@Amelia], `MatchIt` [@MatchIt], and `margins` [@margins] for an incomplete list of `R` packages created primarily for political science research.) 33 | 34 | `ggparliament` is useful research tool for a variety of social science disciplines, including quantitative political science. It is particularly beneficial for political scientists who research political institutions, such as electoral systems, party politics, or legislative politics. `ggparliament` provides several layouts, representing different legislative chambers e.g. the United Kingdom's House of Commons, Australia's horseshoe-shaped parliament, or the widely-used semicircle legislative chamber. 35 | 36 | ![](ggparliament_layouts.png) 37 | 38 | The standard syntax for a `ggparliament` plot is as follows: 39 | 40 | ```{r} 41 | us_data <- ggparliament::election_data %>% 42 | filter(country == "USA" & year == 2016 & 43 | house == "Representatives") %>% 44 | parliament_data(election_data = ., 45 | parl_rows = 8, 46 | party_seats = .$seats, 47 | type = 'semicircle') 48 | 49 | ggplot(us_data, aes(x,y), colour = "black") + 50 | geom_parliament_seats(size = 0.8) + 51 | theme_ggparliament() 52 | ``` 53 | 54 | `ggparliament` has been designed with several key features in mind. It provides multiple layouts for different parliamentary systems, catering to researchers of various political systems. `ggparliament` items can be more complex than what we have detailed here. For example, it is possible to facet the `ggparliament` object over numerous elections or parliaments; this work is further explained in the package documentation. 55 | 56 | In this paper we present a `R` package to plot legislatures, also known as parliament plots. Parliament plots provide summary statistics for the distribution of a legislature, allowing users to view the number of seats per party. In addition, `ggparliament` visualizes descriptive data about legislators or legislative districts as well as election results. 57 | 58 | 59 | # References 60 | -------------------------------------------------------------------------------- /vignettes/e_facet-parliament_5.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "How to facet parliaments by year or house" 3 | author: "Zoe Meers" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Facet Parliament} 8 | %\VignetteEngine{knitr::knitr} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include=FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | 18 | 19 | library(ggparliament) 20 | library(dplyr) 21 | library(ggplot2) 22 | require(tidyr) 23 | require(magrittr) 24 | require(purrr) 25 | 26 | source("../R/parliament_data.R") 27 | source("../R/geom_parliament_seats.R") 28 | source("../R/geom_highlight_government.R") 29 | source("../R/helper_funcs.R") 30 | source("../R/draw_majoritythreshold.R") 31 | source("../R/draw_partylabels.R") 32 | source("../R/draw_majoritythreshold.R") 33 | source("../R/draw_totalseats.R") 34 | source("../R/theme_ggparliament.R") 35 | load("../R/sysdata.rda") 36 | ``` 37 | 38 | 39 | To facet your parliament plot, use the split-apply-combine strategy in a `dplyr` chain. 40 | 41 | ## Steps 42 | You must: 43 | 44 | 1) split by year 45 | 2) apply the coordinates for each party in parliament_data 46 | 3) combine the rows into one large data frame. 47 | 48 | This can be done using map from `purrr`. 49 | A few examples are as follows: 50 | 51 | ### American Congress from 2010 onwards 52 | ```{r} 53 | usa <- election_data %>% 54 | filter(country == "USA" & 55 | house == "Representatives") %>% 56 | split(.$year) %>% # split 57 | map(~ parliament_data( 58 | election_data = ., # apply 59 | party_seats = .$seats, 60 | parl_rows = 8, 61 | type = "semicircle" 62 | )) %>% 63 | bind_rows() # combine 64 | ``` 65 | 66 | ```{r, fig.width=12, fig.height=8} 67 | us <- ggplot(usa, aes(x, y, colour = party_short)) + 68 | geom_parliament_seats(size = 2.8) + 69 | geom_highlight_government(government == 1) + 70 | labs( 71 | colour = NULL, 72 | title = "American Congress", 73 | subtitle = "The party that has control of US Congress is encircled in black." 74 | ) + 75 | theme_ggparliament() + 76 | scale_colour_manual( 77 | values = usa$colour, 78 | limits = usa$party_short 79 | ) + 80 | theme(legend.position = "bottom") + 81 | facet_wrap(~year, ncol = 2) 82 | 83 | us 84 | ``` 85 | 86 | 87 | ### Facet Australian Parliament by House 88 | ```{r} 89 | australia <- election_data %>% 90 | filter(country == "Australia" & 91 | year == "2016") %>% 92 | split(.$house) %>% # split 93 | map(~ parliament_data( 94 | election_data = ., # apply 95 | party_seats = .$seats, 96 | parl_rows = 4, 97 | type = "horseshoe" 98 | )) %>% 99 | bind_rows() # combine 100 | ``` 101 | 102 | ```{r,fig.width=10, fig.height=5} 103 | au <- ggplot(australia, aes(x, y, colour = party_short)) + 104 | geom_parliament_seats(size = 2.7) + 105 | geom_highlight_government(government == 1) + 106 | labs( 107 | colour = NULL, 108 | title = "Australian Parliament", 109 | subtitle = "Government encircled in black." 110 | ) + 111 | scale_colour_manual( 112 | values = australia$colour, 113 | limits = australia$party_short 114 | ) + 115 | theme_ggparliament() + 116 | theme(legend.position = "bottom") + 117 | facet_grid(~house, scales = "free") 118 | 119 | au 120 | ``` 121 | 122 | ### Facet UK Parliament 123 | 124 | ```{r} 125 | uk <- election_data %>% 126 | filter(country == "UK") %>% 127 | split(.$year) %>% 128 | map(~ parliament_data( 129 | election_data = ., 130 | party_seats = .$seats, 131 | group = .$government, 132 | type = "opposing_benches" 133 | )) %>% 134 | bind_rows() 135 | ``` 136 | 137 | 138 | ```{r, fig.height = 6, fig.width=8} 139 | ggplot( 140 | data = uk, 141 | aes( 142 | x = x, 143 | y = y, 144 | color = party_long 145 | ) 146 | ) + 147 | geom_parliament_seats(size = 1.5) + 148 | coord_flip() + 149 | facet_wrap(~year, ncol = 2) + 150 | scale_color_manual( 151 | values = uk$colour, 152 | limits = uk$party_long 153 | ) + 154 | theme_ggparliament() 155 | ``` 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /vignettes/h_arrange_parliament_8.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Arranging Parliament Plots" 3 | author: "Robert Hickman" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Arrange Parliament} 8 | %\VignetteEngine{knitr::knitr} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | ```{r setup, include = FALSE} 12 | knitr::opts_chunk$set( 13 | collapse = TRUE, 14 | comment = "#>" 15 | ) 16 | library(ggparliament) 17 | library(dplyr) 18 | library(ggplot2) 19 | require(tidyr) 20 | require(magrittr) 21 | 22 | source("../R/parliament_data.R") 23 | source("../R/geom_parliament_seats.R") 24 | source("../R/geom_highlight_government.R") 25 | source("../R/helper_funcs.R") 26 | source("../R/draw_majoritythreshold.R") 27 | source("../R/draw_partylabels.R") 28 | source("../R/draw_majoritythreshold.R") 29 | source("../R/draw_totalseats.R") 30 | source("../R/theme_ggparliament.R") 31 | load("../R/sysdata.rda") 32 | ``` 33 | 34 | ## Improving Plot Information via Plot Order 35 | The provided example data for elections is in order of country, year, winning power, and then seats. However, this need not be so. It's easy to imagine downloading data in (e.g.) alphabetical order 36 | ```{r} 37 | unformatted_data <- election_data %>% 38 | filter(country == "Germany" & year == "2017") %>% 39 | arrange(party_long) 40 | head(unformatted_data) 41 | ``` 42 | One simple way to deal with this is to arrange the data before piping it through ggparliament. For instance, in the order I prefer (government on the left, starting with the largest party): 43 | ```{r, fig.width=8, fig.height=4} 44 | formatted_data <- unformatted_data %>% 45 | arrange(-government, -seats) 46 | formatted_parl_data <- formatted_data %>% 47 | parliament_data(., 48 | parl_rows = 12, 49 | party_seats = .$seats, 50 | type = "semicircle") 51 | german_parliament <- ggplot(formatted_parl_data, aes(x, y, colour = party_short)) + 52 | geom_parliament_seats(size = 2.8) + 53 | geom_highlight_government(government == 1) + 54 | draw_majoritythreshold(n = 355, label = FALSE, type = "semicircle") + 55 | labs(colour="Party", 56 | title="Germany 2017 Election Results") + 57 | theme_ggparliament() + 58 | scale_colour_manual(values = formatted_parl_data$colour, 59 | limits = formatted_parl_data$party_short) 60 | german_parliament 61 | ``` 62 | 63 | However, for whatever reason this might not be possible, or just undesirable. To deal with this, parliament_data also includes the ability to order the data for plotting using plot_order. If this is left as NULL, no ordering takes place. 64 | 65 | ```{r, fig.width=8, fig.height=4} 66 | german_parliament <- unformatted_data %>% 67 | parliament_data(., 68 | parl_rows = 12, 69 | party_seats = .$seats, 70 | plot_order = .$seats, 71 | type = "semicircle") %>% 72 | ggplot(., aes(x, y, colour = party_short)) + 73 | geom_parliament_seats(size = 2.8) + 74 | geom_highlight_government(government == 1) + 75 | draw_majoritythreshold(n = 355, label = FALSE, type = "semicircle") + 76 | labs(colour="Party", 77 | title="Germany 2017 Election Results Arranged by Seats per Party") + 78 | theme_ggparliament() + 79 | scale_colour_manual(values = unformatted_data$colour, 80 | limits = unformatted_data$party_short) 81 | german_parliament 82 | 83 | ``` 84 | Given that government is a binary variable, the simplest way to order as in the first plot is to multiple this by the number of seats, i.e.: 85 | 86 | ```{r, fig.width=8, fig.height=4} 87 | german_parliament <- unformatted_data %>% 88 | parliament_data(., 89 | parl_rows = 12, 90 | party_seats = .$seats, 91 | plot_order = .$seats * .$government, 92 | type = "semicircle") %>% 93 | ggplot(., aes(x, y, colour = party_short)) + 94 | geom_parliament_seats(size = 2.8) + 95 | geom_highlight_government(government == 1) + 96 | draw_majoritythreshold(n = 355, label = FALSE, type = "semicircle") + 97 | labs(colour="Party", 98 | title="Germany 2017 Election Results Arranged by Seats per Party") + 99 | theme_ggparliament() + 100 | scale_colour_manual(values = unformatted_data$colour, 101 | limits = unformatted_data$party_short) 102 | german_parliament 103 | 104 | ``` 105 | -------------------------------------------------------------------------------- /R/draw_majoritythreshold.R: -------------------------------------------------------------------------------- 1 | #' Draw majority threshold 2 | #' @param n The number of seats required for a majority 3 | #' @param label A logical variable for labelling majority threshold. Defaults to TRUE. 4 | #' @param type Type of parliament (horseshoe, semicircle,opposing benches) 5 | #' @param linecolour The colour of the majority line. Defaults to gray. 6 | #' @param linesize The size of the line. Defaults to 1. 7 | #' @param linetype The style of the line. Defaults to 2, or a dashed line. 8 | #' @param linealpha Set the transparency of the line. Defaults to 1. 9 | #' @examples 10 | #' data <- election_data[ 11 | #' election_data$country == "USA" & 12 | #' election_data$house == "Representatives" & 13 | #' election_data$year == "2016", 14 | #' ] 15 | #' usa_data <- parliament_data( 16 | #' election_data = data, 17 | #' type = "semicircle", 18 | #' party_seats = data$seats, 19 | #' parl_rows = 8 20 | #' ) 21 | #' ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 22 | #' geom_parliament_seats() + 23 | #' draw_majoritythreshold( 24 | #' n = 218, 25 | #' label = TRUE, 26 | #' type = "semicircle" 27 | #' ) + 28 | #' theme_ggparliament() 29 | #' @author Zoe Meers 30 | #' @export 31 | #' @importFrom ggplot2 ggplot_add 32 | 33 | 34 | 35 | draw_majoritythreshold <- function(n = NULL, 36 | label = TRUE, 37 | type = c("horseshoe", "semicircle", "opposing_benches"), 38 | linecolour = "black", 39 | linesize = 1, 40 | linetype = 2, 41 | linealpha = 1) { 42 | structure( 43 | list( 44 | n = n, 45 | type = type, 46 | label = label, 47 | linecolour = linecolour, 48 | linesize = linesize, 49 | linetype = linetype, 50 | linealpha = linealpha 51 | ), 52 | class = "majorityLine" 53 | ) 54 | } 55 | 56 | # calculate the positions of the thresholds 57 | #' @export 58 | ggplot_add.majorityLine <- function(object, plot, object_name) { 59 | filter <- group_by <- NULL 60 | new_dat <- dplyr::filter(plot$data, dplyr::row_number() == object$n) 61 | x_pos <- new_dat$x 62 | y_pos_oppbenches <- new_dat$y[1] 63 | 64 | if (object$type == "semicircle") { 65 | if (!object$label) { 66 | plot + 67 | ggplot2::geom_segment(ggplot2::aes(y = 0.8, yend = max(plot$data$y) + 0.1, x = 0, xend = 0), colour = object$linecolour, size = object$linesize, linetype = object$linetype, alpha = object$linealpha) 68 | } else { 69 | plot + 70 | ggplot2::geom_segment(ggplot2::aes(y = 0.8, yend = max(plot$data$y) + 0.1, x = 0, xend = 0), colour = object$linecolour, size = object$linesize, linetype = object$linetype, alpha = object$linealpha) + 71 | ggplot2::annotate("text", x = 0.85, y = max(plot$data$y) + 0.1, label = paste0(object$n, " seats needed for a majority.")) 72 | } 73 | } else { 74 | if (object$type == "horseshoe") { 75 | if (!object$label) { 76 | plot + 77 | ggplot2::geom_segment(ggplot2::aes(y = 7.5, yend = 10.5, x = 0, xend = 0), colour = object$linecolour, size = object$linesize, linetype = object$linetype, alpha = object$linealpha) 78 | } else { 79 | plot + 80 | ggplot2::geom_segment(ggplot2::aes(y = 7.5, yend = 10.5, x = 0, xend = 0), colour = object$linecolour, size = object$linesize, linetype = object$linetype, alpha = object$linealpha) + 81 | ggplot2::annotate("text", x = 0, y = 6, label = paste0(object$n, " seats\nneeded for a\nmajority.")) 82 | } 83 | } else { 84 | if (object$type == "opposing_benches") { 85 | if (!object$label) { 86 | plot + 87 | ggplot2::geom_segment(aes(y = y_pos_oppbenches + 0.5, yend = y_pos_oppbenches + 0.5, x = min(plot$data$x), xend = max(plot$data$x) / 2), 88 | colour = object$linecolour, size = object$linesize, linetype = object$linetype, alpha = object$linealpha 89 | ) 90 | } else { 91 | plot + 92 | ggplot2::geom_segment(aes(y = y_pos_oppbenches + 0.5, yend = y_pos_oppbenches + 0.5, x = min(plot$data$x), xend = max(plot$data$x) / 2), 93 | colour = object$linecolour, size = object$linesize, linetype = object$linetype, alpha = object$linealpha 94 | ) + 95 | ggplot2::annotate("text", x = max(plot$data$x) / 1.9, y = y_pos_oppbenches - (y_pos_oppbenches / 15), label = paste0(object$n, " seats needed\nfor a majority.")) 96 | } 97 | } else { 98 | warning("Warning: parliament layout not supported.") 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /vignettes/c_draw-majority-threshold_3.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "How to draw the majority threshold" 3 | author: "Zoe Meers" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Draw Majorities} 8 | %\VignetteEngine{knitr::knitr} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include=FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | 18 | 19 | library(ggparliament) 20 | library(dplyr) 21 | library(ggplot2) 22 | require(tidyr) 23 | require(magrittr) 24 | 25 | source("../R/parliament_data.R") 26 | source("../R/geom_parliament_seats.R") 27 | source("../R/geom_highlight_government.R") 28 | source("../R/helper_funcs.R") 29 | source("../R/draw_majoritythreshold.R") 30 | source("../R/draw_partylabels.R") 31 | source("../R/draw_majoritythreshold.R") 32 | source("../R/draw_totalseats.R") 33 | source("../R/theme_ggparliament.R") 34 | load("../R/sysdata.rda") 35 | 36 | 37 | ``` 38 | 39 | Majority thresholds 40 | 41 | The majority threshold marks the point where one group has half or more than half of the seats in parliament. To draw the majority threshold on a parliament plot, the user should input the number that constitues a majority as well as the type of parliament. The function plots a line through the majority seat. By default, the majority threshold adds an annotation noting the seats required for a government to form. This can be turned off by writing `label = FALSE`. 42 | 43 | Some examples are as follows: 44 | 45 | ```{r, fig.height=4, fig.width=8} 46 | usa_12 <- election_data %>% 47 | filter(country == "USA" & 48 | house == "Representatives" & 49 | year == "2012") %>% 50 | parliament_data(election_data = ., 51 | party_seats = .$seats, 52 | parl_rows = 8, 53 | type = "semicircle") 54 | 55 | ggplot(usa_12, aes(x, y, colour = party_short)) + 56 | geom_parliament_seats() + 57 | geom_highlight_government(government == 1) + 58 | draw_majoritythreshold(n = 218, 59 | type = "semicircle") + 60 | theme_ggparliament() + 61 | labs(colour = NULL, 62 | title = "2012 American Congress", 63 | subtitle = "Party that controls the chamber is highlighted in black.") + 64 | scale_colour_manual(values = usa_12$colour, 65 | limits = usa_12$party_short) 66 | 67 | ``` 68 | 69 | ```{r, fig.height=4, fig.width=5} 70 | #get the data for the last election 71 | uk_data <- election_data %>% 72 | filter(country == "UK") %>% 73 | filter(year == 2017) %>% 74 | #parl_data it out 75 | parliament_data(election_data = ., 76 | party_seats = .$seats, 77 | group = .$government, 78 | parl_rows = NULL, 79 | type = "opposing_benches") 80 | #note that for opposing benches, parliament_data tries to calculate a number of rows per dot 81 | #that allows clear visualisation of the majority line 82 | #try to use a number of rows that is an exact divisor of the threshold 83 | 84 | colscale = 85 | 86 | #plot it 87 | uk <- ggplot(uk_data, aes(x, y, colour = party_short)) + 88 | scale_colour_manual(values = unique(uk_data$colour), 89 | limits = unique(uk_data$party_short), 90 | name = "Party") + 91 | geom_parliament_seats(size = 1.5) + 92 | draw_majoritythreshold(n = 325, type = "opposing_benches") + 93 | coord_flip() + 94 | theme_ggparliament() + 95 | theme(legend.position = c("bottom")) 96 | 97 | uk 98 | 99 | ``` 100 | 101 | ```{r,fig.width=6, fig.height=6} 102 | australia <- election_data %>% 103 | filter(country == "Australia" & 104 | house == "Representatives" & 105 | year == 2016) 106 | 107 | australia1 <- parliament_data(election_data = australia, 108 | party_seats = australia$seats, 109 | parl_rows = 4, 110 | type = "horseshoe") 111 | 112 | au <-ggplot(australia1, aes(x, y, colour = party_short)) + 113 | geom_parliament_seats() + 114 | geom_highlight_government(government == 1) + 115 | draw_majoritythreshold(n = 76, 116 | type = "horseshoe") + 117 | theme_ggparliament() + 118 | labs(colour = NULL, 119 | title = "Australian Parliament", 120 | subtitle = "Government encircled in black.") + 121 | scale_colour_manual(values = australia$colour, 122 | limits = australia$party_short) + 123 | theme(legend.position = 'bottom') 124 | au 125 | ``` 126 | 127 | 128 | ```{r, fig.height=5, fig.width=10} 129 | germany <- election_data %>% 130 | filter(year == 2017 & 131 | country == "Germany") 132 | 133 | germany <- parliament_data(election_data = germany, 134 | parl_rows = 12, 135 | party_seats = germany$seats, 136 | plot_order = germany$government, 137 | type = 'semicircle') 138 | 139 | german_parliament <- ggplot(germany, aes(x, y, colour = party_short)) + 140 | geom_parliament_seats() + 141 | geom_highlight_government(government == 1) + 142 | draw_majoritythreshold(n = 355, label = FALSE, type = "semicircle") + 143 | labs(colour="Party", 144 | title="Germany 2017 Election Results") + 145 | theme_ggparliament() + 146 | scale_colour_manual(values = germany$colour, 147 | limits = germany$party_short) 148 | german_parliament 149 | ``` -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /R/draw_partylabels.R: -------------------------------------------------------------------------------- 1 | #' Draw labels for political parties and seats per party 2 | #' @param party_names A column containing party names. 3 | #' @param party_seats A column containing party seats. 4 | #' @param party_colours A column containing party colours. 5 | #' @param names If TRUE, finds party names from data. Defaults to TRUE. 6 | #' @param seats If TRUE, finds party seats from data. Defaults to TRUE. 7 | #' @param type Define type. Currently only supports semicircle and horseshoe style parliaments. 8 | #' @examples 9 | #' data <- election_data[ 10 | #' election_data$country == "USA" & 11 | #' election_data$house == "Representatives" & 12 | #' election_data$year == "2016", 13 | #' ] 14 | #' usa_data <- parliament_data( 15 | #' election_data = data, 16 | #' type = "semicircle", 17 | #' party_seats = data$seats, 18 | #' parl_rows = 8 19 | #' ) 20 | #' ggplot2::ggplot(usa_data, ggplot2::aes(x, y, colour = party_long)) + 21 | #' geom_parliament_seats() + 22 | #' draw_partylabels( 23 | #' type = "semicircle", 24 | #' party_names = party_long, 25 | #' party_seats = seats, 26 | #' party_colours = colour 27 | #' ) + 28 | #' ggplot2::scale_colour_manual( 29 | #' values = usa_data$colour, 30 | #' limits = usa_data$party_long 31 | #' ) + 32 | #' theme_ggparliament() 33 | #' @author Zoe Meers 34 | #' @export 35 | #' @importFrom ggplot2 ggplot_add 36 | 37 | 38 | draw_partylabels <- function(type = c("semicircle", "horseshoe"), 39 | names = TRUE, 40 | seats = TRUE, 41 | party_names = party_names, 42 | party_colours = party_colours, 43 | party_seats = party_seats) { 44 | structure( 45 | list( 46 | type = type, 47 | names = names, 48 | seats = seats, 49 | party_names = rlang::enquo(party_names), 50 | party_seats = rlang::enquo(party_seats), 51 | party_colours = rlang::enquo(party_colours) 52 | ), 53 | class = "partyLabels" 54 | ) 55 | } 56 | 57 | #' @export 58 | ggplot_add.partyLabels <- function(object, plot, object_name) { 59 | x <- y <- filter <- group_by <- summarise <- NULL 60 | 61 | # calculate the positions of the labels 62 | filt_data <- dplyr::filter(plot$data, row == max(row)) 63 | group_data <- dplyr::group_by(filt_data, pn = !!object$party_names, ps = !!object$party_seats, pc = !!object$party_colours) 64 | new_dat <- dplyr::summarise(group_data, mean_x = mean(x), mean_y = mean(y)) 65 | 66 | pos_movement_horseshoe <- c(new_dat$mean_x + 2) 67 | pos_movement_semicircle <- c(new_dat$mean_x + 0.8) 68 | neg_movement_horseshoe <- c(new_dat$mean_x - 2) 69 | neg_movement_semicircle <- c(new_dat$mean_x - 0.8) 70 | 71 | 72 | if (object$type == "horseshoe") { 73 | if (!(object$names) & !(object$seats)) { 74 | plot 75 | } else if (!(object$names) & object$seats) { 76 | plot + ggplot2::annotate("text", 77 | x = ifelse(new_dat$mean_x > 0, 78 | pos_movement_horseshoe, 79 | neg_movement_horseshoe 80 | ), 81 | y = new_dat$mean_y, 82 | label = new_dat$ps, 83 | colour = new_dat$pc, 84 | vjust = "outward" 85 | ) 86 | } else if (object$names & !(object$seats)) { 87 | plot + 88 | ggplot2::annotate("text", 89 | x = ifelse(new_dat$mean_x > 0, 90 | pos_movement_horseshoe, 91 | neg_movement_horseshoe 92 | ), 93 | y = new_dat$mean_y, 94 | label = new_dat$pn, 95 | colour = new_dat$pc, 96 | vjust = "outward" 97 | ) 98 | } else if (object$names & object$seats) { 99 | plot + 100 | ggplot2::annotate("text", 101 | x = ifelse(new_dat$mean_x > 0, 102 | pos_movement_horseshoe, 103 | neg_movement_horseshoe 104 | ), 105 | y = new_dat$mean_y, 106 | label = paste0(new_dat$pn, "\n(", new_dat$ps, ")"), 107 | colour = new_dat$pc, 108 | vjust = "outward" 109 | ) 110 | } 111 | } else if (object$type == "semicircle") { 112 | if (!(object$names) & !(object$seats)) { 113 | plot 114 | } else if (!(object$names) & object$seats) { 115 | plot + 116 | ggplot2::annotate("text", 117 | x = ifelse(new_dat$mean_x > 0, 118 | pos_movement_semicircle, 119 | neg_movement_semicircle 120 | ), 121 | y = new_dat$mean_y, 122 | label = new_dat$ps, 123 | colour = new_dat$pc, 124 | vjust = "outward" 125 | ) 126 | } else if (object$names & !(object$seats)) { 127 | plot + 128 | ggplot2::annotate("text", 129 | x = ifelse(new_dat$mean_x > 0, 130 | pos_movement_semicircle, 131 | neg_movement_semicircle 132 | ), 133 | y = new_dat$mean_y, 134 | label = new_dat$pn, 135 | colour = new_dat$pc, 136 | vjust = "outward" 137 | ) 138 | } 139 | else if (object$names & object$seats) { 140 | plot + 141 | ggplot2::annotate("text", 142 | x = ifelse(new_dat$mean_x > 0, 143 | pos_movement_semicircle, 144 | neg_movement_semicircle 145 | ), 146 | y = new_dat$mean_y, 147 | label = paste0(new_dat$pn, "\n(", new_dat$ps, ")"), 148 | colour = new_dat$pc, 149 | vjust = "outward" 150 | ) 151 | } 152 | } 153 | 154 | else { 155 | warning("Warning: parliament layout is not supported.") 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | License • ggparliament 6 | 7 | 8 |
    9 |
    71 | 72 | 73 | 74 |
    75 |
    76 | 79 | 80 |
    YEAR: 2018
     81 | COPYRIGHT HOLDER: Robert Hickman
     82 | 
    83 | 84 |
    85 | 86 | 89 | 90 |
    91 | 92 | 93 | 94 |
    97 | 98 |
    99 |

    Site built with pkgdown 2.0.7.

    100 |
    101 | 102 |
    103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /R/parliament_data.R: -------------------------------------------------------------------------------- 1 | #' A function that prepares data for parliamentary plots 2 | #' @param election_data aggregate election results 3 | #' @param parl_rows number of rows in parliament 4 | #' @param party_seats seats per party 5 | #' @param plot_order plot the data in a specified order 6 | #' @param group grouping variable for separate chunks. e.g. opposing benches in UK parliament 7 | #' @param type type of parliament (horseshoe, semicircle, circle, classroom, opposing benches) 8 | #' 9 | #' @examples 10 | #' data <- election_data[ 11 | #' election_data$country == "USA" & 12 | #' election_data$house == "Representatives" & 13 | #' election_data$year == "2016", 14 | #' ] 15 | #' usa_data <- parliament_data( 16 | #' election_data = data, 17 | #' type = "semicircle", 18 | #' party_seats = data$seats, 19 | #' parl_rows = 8 20 | #' ) 21 | #' @author 22 | #' Zoe Meers, Rob Hickman 23 | #' @export 24 | parliament_data <- function(election_data = NULL, 25 | parl_rows = NULL, 26 | party_seats = election_data$seats, 27 | group = NULL, 28 | plot_order = NULL, 29 | type = c( 30 | "horseshoe", 31 | "semicircle", 32 | "thirdcircle", 33 | "third_circle", 34 | "circle", 35 | "classroom", 36 | "opposing_benches" 37 | )) { 38 | tail <- head <- first <- NULL 39 | 40 | # for horseshoe shaped parliaments- e.g. Australia 41 | if (type == "horseshoe") { 42 | # calculate the layout of the final plot from supplied data 43 | parl_layout <- calc_coordinates(sum(party_seats), parl_rows, c(8, 10)) 44 | } 45 | 46 | else if (type == "semicircle") { 47 | parl_layout <- calc_coordinates(sum(party_seats), parl_rows, c(1, 2)) 48 | } 49 | 50 | else if (type == "thirdcircle" | type == "third_circle") { 51 | parl_layout <- calc_coordinates(sum(party_seats), parl_rows, c(1, 2), segment = 1/3) 52 | } 53 | 54 | else if (type == "circle") { 55 | parl_layout <- calc_coordinates(sum(party_seats), parl_rows, c(1, 2), segment = 1) 56 | } 57 | 58 | else if (type == "classroom") { 59 | # calculate parl_layout by expanding a grid of rows vs the length each row needs to be 60 | parl_layout <- expand.grid( 61 | y = 1:parl_rows, 62 | x = seq_len(ceiling(sum(party_seats) / parl_rows)) 63 | ) 64 | 65 | # remove the extra seats that are added by expanding a grid 66 | # removes from either end of back row 67 | leftovers <- nrow(parl_layout) - sum(party_seats) 68 | parl_layout <- parl_layout[-which(parl_layout$y == max(parl_layout$y) & 69 | parl_layout$x %in% c( 70 | tail(1:max(parl_layout$x), leftovers / 2), 71 | head(1:max(parl_layout$x), leftovers / 2) 72 | )), ] 73 | } 74 | 75 | else if (type == "opposing_benches") { 76 | # get the seats for each group 77 | # opposing benches by definition needs grouping for each bench 78 | gov_seats <- sum(party_seats[which(group == 1)]) 79 | opp_seats <- sum(party_seats[which(group == 0)]) 80 | 81 | bench_seats <- c(gov_seats, opp_seats) 82 | 83 | threshold <- ceiling(sum(gov_seats, opp_seats) / 2) 84 | 85 | if (!is.null(parl_rows)) { 86 | nrows <- parl_rows 87 | } else { 88 | # if there is a nice divisor for the majority threshold use this 89 | # else use 12 90 | nrows <- which(threshold %% seq_len(threshold) == 0) 91 | 92 | if (any(nrows > 10 & nrows < 15)) { 93 | nrows <- nrows[first(which(nrows > 10))] 94 | } else { 95 | nrows <- 12 96 | } 97 | } 98 | 99 | # lapply expanding the group 100 | parl_layout <- lapply(bench_seats, function(seats, rows) { 101 | parl_layout <- expand.grid(x = 1:rows, y = seq_len(ceiling(seats / rows))) 102 | leftovers <- nrow(parl_layout) - seats 103 | 104 | # legacy code for taking leftovers from both sides 105 | # decided to do it from right side only 106 | # parl_layout <- parl_layout[-which(parl_layout$y == max(parl_layout$y) & 107 | # parl_layout$x %in% c( 108 | # tail(1:max(parl_layout$x), leftovers / 2), 109 | # head(1:max(parl_layout$x), leftovers / 2) 110 | # )), ] 111 | 112 | parl_layout <- parl_layout[-((nrow(parl_layout) - leftovers) + 1:nrow(parl_layout)), ] 113 | 114 | return(parl_layout) 115 | }, rows = nrows) 116 | 117 | # the x axis space between the two benches 118 | spacer <- 5 119 | 120 | # space the benches and rbind 121 | parl_layout[[2]]$x <- parl_layout[[2]]$x + max(parl_layout[[1]]$x + spacer) 122 | parl_layout <- rbind(parl_layout[[1]], parl_layout[[2]]) 123 | 124 | # bind in the election data 125 | # can probably be parsed out to later if we include grouping in other geoms 126 | election_data <- election_data[order(-group, -party_seats), ] 127 | } 128 | 129 | else if (is.null(type) | !type %in% c("horseshoe", "thirdcircle", 130 | "third_circle", "semicircle", "circle", "classroom", "opposing_benches")) { 131 | if (is.null(type)) { 132 | type_name <- "" 133 | } else { 134 | type_name <- type 135 | } 136 | warning("Warning: parliament layout \"", type_name, "\" not supported.") 137 | } 138 | 139 | # if election data is not null, bind layout to original data 140 | if (!is.null(election_data)) { 141 | if (type != "opposing_benches") { 142 | parl_data <- as.data.frame(election_data[rep(row.names(election_data), party_seats), ]) 143 | 144 | if (!is.null(plot_order)) { 145 | # order the data not by seats- e.g. by government then seats 146 | parl_data <- parl_data[order(-rep(plot_order, party_seats)), ] 147 | } 148 | } else { 149 | parl_data <- as.data.frame(election_data[rep(row.names(election_data), party_seats[order(-group, -party_seats)]), ]) 150 | # not implemented ordering yet- seems unlikely it would ever not be by largest party in bench system? 151 | } 152 | 153 | parl_layout <- cbind(parl_data, parl_layout) 154 | } 155 | 156 | return(parl_layout) 157 | } 158 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • ggparliament 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 |
    24 |
    94 | 95 | 96 | 97 | 98 |
    99 |
    100 | 103 | 104 | Content not found. Please use links in the navbar. 105 | 106 |
    107 | 108 | 112 | 113 |
    114 | 115 | 116 | 117 |
    121 | 122 |
    123 |

    124 |

    Site built with pkgdown 2.0.7.

    125 |
    126 | 127 |
    128 |
    129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /docs/reference/ggparliament-package.html: -------------------------------------------------------------------------------- 1 | 2 | ggparliament — ggparliament-package • ggparliament 6 | 7 | 8 |
    9 |
    71 | 72 | 73 | 74 |
    75 |
    76 | 81 | 82 |
    83 |

    ggparliament

    84 |
    85 | 86 | 87 | 88 |
    89 | 92 |
    93 | 94 | 95 |
    98 | 99 |
    100 |

    Site built with pkgdown 2.0.7.

    101 |
    102 | 103 |
    104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /docs/reference/ggplot2-ggproto.html: -------------------------------------------------------------------------------- 1 | 2 | ggplot2-ggproto — GeomParliamentSeats • ggparliament 6 | 7 | 8 |
    9 |
    71 | 72 | 73 | 74 |
    75 |
    76 | 81 | 82 |
    83 |

    ggplot2-ggproto

    84 |
    85 | 86 | 87 | 88 |
    89 | 92 |
    93 | 94 | 95 |
    98 | 99 |
    100 |

    Site built with pkgdown 2.0.7.

    101 |
    102 | 103 |
    104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • ggparliament 6 | 7 | 8 |
    9 |
    71 | 72 | 73 | 74 |
    103 | 104 | 105 |
    108 | 109 |
    110 |

    Site built with pkgdown 2.0.7.

    111 |
    112 | 113 |
    114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.html: -------------------------------------------------------------------------------- 1 | 2 | Contributing to ggparliament • ggparliament 6 | 7 | 8 |
    9 |
    71 | 72 | 73 | 74 |
    75 |
    76 | 79 | 80 |
    81 | 82 |

    Thank you for any contributions. We welcome contributions from all, regardless of your programming experience.

    83 |
    84 |

    Types of contributions

    85 |

    We would love to hear from anyone who is willing to provide their time and help.

    86 |

    Here is a non-exhaustive list of things that we might need help with: 1. Election data 2. Adding additional information about legislatures or electoral systems 3. Extending interactive ggparliament objects 4. Writing tutorials or vignettes 5. Fix bugs

    87 |
    88 |
    89 |

    How to contribute code or data

    90 |
    1. Fork this repository
    2. 91 |
    3. Make your changes and commit to your GitHub fork.
    4. 92 |
    5. Open an issue here and submit a pull request.
    6. 93 |
    94 |
    95 | 96 |
    97 | 98 | 101 | 102 |
    103 | 104 | 105 | 106 |
    109 | 110 |
    111 |

    Site built with pkgdown 2.0.7.

    112 |
    113 | 114 |
    115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • ggparliament 6 | 7 | 8 |
    9 |
    71 | 72 | 73 | 74 |
    75 |
    76 |
    77 | 80 | 81 | 82 |
    • 83 |

      Robert Hickman. Author. 84 |

      85 |
    • 86 |
    • 87 |

      Zoe Meers. Author, maintainer. 88 |

      89 |
    • 90 |
    • 91 |

      Thomas J. Leeper. Author. 92 |

      93 |
    • 94 |
    95 |
    96 |
    97 |

    Citation

    98 | Source: DESCRIPTION 99 |
    100 |
    101 | 102 | 103 |

    Hickman R, Meers Z, Leeper T (2024). 104 | ggparliament: Parliament Plots. 105 | R package version 3.1.6, https://github.com/zmeers/ggparliament. 106 |

    107 |
    @Manual{,
    108 |   title = {ggparliament: Parliament Plots},
    109 |   author = {Robert Hickman and Zoe Meers and Thomas J. Leeper},
    110 |   year = {2024},
    111 |   note = {R package version 3.1.6},
    112 |   url = {https://github.com/zmeers/ggparliament},
    113 | }
    114 | 115 |
    116 | 117 |
    118 | 119 | 120 | 121 |
    124 | 125 |
    126 |

    Site built with pkgdown 2.0.7.

    127 |
    128 | 129 |
    130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | # `ggparliament`: Parliament plots 6 | 7 | 8 | ![CRAN Status](https://www.r-pkg.org/badges/version/ggparliament) 9 | ![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/ggparliament) 10 | [![DOI](https://joss.theoj.org/papers/10.21105/joss.01313/status.svg)](https://doi.org/10.21105/joss.01313) 11 | 12 | This package attempts to implement "parliament plots" - visual representations of the composition of legislatures that display seats colour-coded by party. The input is a data frame containing one row per party, with columns representing party name/label and number of seats, respectively. 13 | 14 | This `R` package is a `ggplot2` extension and is now on CRAN. Please install the stable version in `R` by running: 15 | 16 | 17 | ```r 18 | install.packages("ggparliament") 19 | ``` 20 | 21 | To install the package from source: 22 | 23 | ```r 24 | devtools::install_github("zmeers/ggparliament") 25 | ``` 26 | 27 | Inspiration from this package comes from: [parliamentdiagram](https://github.com/slashme/parliamentdiagram), which 28 | is used on Wikipedia, [parliament-svg](https://github.com/juliuste/parliament-svg), which is a javascript clone, and [a discussion on StackOverflow](https://stackoverflow.com/questions/42729174/creating-a-half-donut-or-parliamentary-seating-chart), which provided some of the code for part for the "arc" representations used in this package. 29 | 30 | 31 | If you have any issues, please note the problem and inform us! 32 | 33 | 34 | ## Election data 35 | 36 | `ggparliament` provides election data from the following countries. 37 | 38 | 39 | ```r 40 | election_data %>% 41 | distinct(year, country, house) %>% 42 | arrange(country, year) 43 | ``` 44 | 45 | ``` 46 | ## # A tibble: 39 x 3 47 | ## country year house 48 | ## 49 | ## 1 Australia 2010 Representatives 50 | ## 2 Australia 2010 Senate 51 | ## 3 Australia 2013 Representatives 52 | ## 4 Australia 2013 Senate 53 | ## 5 Australia 2016 Representatives 54 | ## 6 Australia 2016 Senate 55 | ## 7 Australia 2019 Representatives 56 | ## 8 Australia 2019 Senate 57 | ## 9 Chile 2009 Diputados 58 | ## 10 Chile 2009 Senadores 59 | ## # … with 29 more rows 60 | ``` 61 | 62 | We also provide the following vignettes for further explanation: 63 | 64 | 1. Basic parliament plots 65 | 2. Labelling parties 66 | 3. Drawing the majority threshold line 67 | 4. Highlighting parties in power 68 | 5. Faceting legislatures 69 | 6. Emphasizing certain seats 70 | 7. Visualizaing overhang seats in MMP electoral systems 71 | 8. Arranging seat order in ggparliament plots. 72 | 73 | Quick `ggparliament` examples can be viewed below. 74 | 75 | ## Semicircle parliament 76 | 77 | ### EU, France, United States, and so on... 78 | 79 | 80 | ### Plot of US House of Representatives 81 | 82 | 83 | 84 | ```r 85 | #filter the election data for the most recent US House of Representatives 86 | us_house <- election_data %>% 87 | filter(country == "USA" & 88 | year == 2016 & 89 | house == "Representatives") 90 | 91 | us_house <- parliament_data(election_data = us_house, 92 | type = "semicircle", 93 | parl_rows = 10, 94 | party_seats = us_house$seats) 95 | 96 | us_senate <- election_data %>% 97 | filter(country == "USA" & 98 | year == 2016 & 99 | house == "Senate") 100 | 101 | us_senate <- parliament_data( 102 | election_data = us_senate, 103 | type = "semicircle", 104 | parl_rows = 4, 105 | party_seats = us_senate$seats) 106 | ``` 107 | 108 | 109 | ```r 110 | representatives <- ggplot(us_house, aes(x, y, colour = party_short)) + 111 | geom_parliament_seats() + 112 | #highlight the party in control of the House with a black line 113 | geom_highlight_government(government == 1) + 114 | #draw majority threshold 115 | draw_majoritythreshold(n = 218, label = TRUE, type = 'semicircle')+ 116 | #set theme_ggparliament 117 | theme_ggparliament() + 118 | #other aesthetics 119 | labs(colour = NULL, 120 | title = "United States House of Representatives", 121 | subtitle = "Party that controls the House highlighted.") + 122 | scale_colour_manual(values = us_house$colour, 123 | limits = us_house$party_short) 124 | 125 | representatives 126 | ``` 127 | 128 | ![US House of Representatives](docs/figure/unnamed-chunk-6-1.png) 129 | 130 | ### Plot of US Senate 131 | 132 | 133 | ```r 134 | senate <- ggplot(us_senate, aes(x, y, colour = party_long)) + 135 | geom_parliament_seats() + 136 | geom_highlight_government(government == 1) + 137 | # add bar showing proportion of seats by party in legislature 138 | geom_parliament_bar(colour = colour, party = party_long) + 139 | theme_ggparliament(legend = FALSE) + 140 | labs(colour = NULL, 141 | title = "United States Senate", 142 | subtitle = "The party that has control of the Senate is encircled in black.") + 143 | scale_colour_manual(values = us_senate$colour, 144 | limits = us_senate$party_long) 145 | senate 146 | ``` 147 | 148 | ![US Senate](docs/figure/unnamed-chunk-7-1.png) 149 | 150 | 151 | ### Plot of German Bundestag 152 | 153 | 154 | ```r 155 | germany <- election_data %>% 156 | filter(year == 2017 & 157 | country == "Germany") 158 | 159 | germany <- parliament_data(election_data = germany, 160 | parl_rows = 10, 161 | type = 'semicircle', 162 | party_seats = germany$seats) 163 | 164 | bundestag <- ggplot(germany, aes(x, y, colour = party_short)) + 165 | geom_parliament_seats(size = 3) + 166 | labs(colour="Party") + 167 | theme_ggparliament(legend = TRUE) + 168 | scale_colour_manual(values = germany$colour, 169 | limits = germany$party_short) 170 | 171 | bundestag 172 | ``` 173 | 174 | ![German Bundestag](docs/figure/unnamed-chunk-8-1.png) 175 | 176 | ## Opposing Benches Parliament 177 | 178 | 179 | 180 | ### United Kingdom 181 | 182 | 183 | ```r 184 | #data preparation 185 | uk_17 <- election_data %>% 186 | filter(country == "UK" & 187 | year == "2017") %>% 188 | parliament_data(election_data = ., 189 | party_seats = .$seats, 190 | parl_rows = 12, 191 | type = "opposing_benches", 192 | group = .$government) 193 | 194 | 195 | commons <- ggplot(uk_17, aes(x, y, colour = party_short)) + 196 | geom_parliament_seats(size = 3) + 197 | theme_ggparliament() + 198 | coord_flip() + 199 | labs(colour = NULL, 200 | title = "UK parliament in 2017") + 201 | scale_colour_manual(values = uk_17$colour, 202 | limits = uk_17$party_short) 203 | 204 | commons 205 | ``` 206 | 207 | ![UK Parliament](docs/figure/unnamed-chunk-9-1.png) 208 | 209 | 210 | 211 | ## Horseshoe parliament 212 | 213 | ### Australia, New Zealand 214 | 215 | 216 | ```r 217 | australia <- election_data %>% 218 | filter(country == "Australia" & 219 | house == "Representatives" & 220 | year == 2016) %>% 221 | parliament_data(election_data = ., 222 | party_seats = .$seats, 223 | parl_rows = 4, 224 | type = "horseshoe") 225 | ``` 226 | 227 | ### Plot of Australian parliament 228 | 229 | 230 | ```r 231 | au_rep <-ggplot(australia, aes(x, y, colour = party_short)) + 232 | geom_parliament_seats(size = 3.5) + 233 | geom_highlight_government(government == 1, colour = "pink", size = 4) + 234 | draw_majoritythreshold(n = 76, 235 | label = TRUE, 236 | linesize = 0.5, 237 | type = 'horseshoe') + 238 | theme_ggparliament() + 239 | theme(legend.position = 'bottom') + 240 | labs(colour = NULL, 241 | title = "Australian Parliament", 242 | subtitle = "Government circled in pink.") + 243 | scale_colour_manual(values = australia$colour, 244 | limits = australia$party_short) 245 | 246 | au_rep 247 | ``` 248 | 249 | ![Australian Parliament](docs/figure/unnamed-chunk-11-1.png) 250 | 251 | 252 | 253 | 254 | 255 | -------------------------------------------------------------------------------- /docs/reference/election_data.html: -------------------------------------------------------------------------------- 1 | 2 | Election data from 5 countries — election_data • ggparliament 7 | 8 | 9 |
    10 |
    72 | 73 | 74 | 75 |
    76 |
    77 | 82 | 83 |
    84 |

    A dataset containing the results of 3 elections for parliamentary houses from 85 | Russia, Australia, Germany, UK and USA. The variables are as follows:

    86 |
    87 | 88 |
    89 |
    data(election_data)
    90 |
    91 | 92 |
    93 |

    Format

    94 |

    A data frame with 167 rows and 8 variables

    95 |
    96 |
    97 |

    Details

    98 | 99 |
    • year. The year of the election (1990-2017)

    • 100 |
    • country. The country the election took place within (Russia, Australia, Germany, UK, USA)

    • 101 |
    • house. The parliamentary house of the election

    • 102 |
    • party_long. The full name of a party which had elected representatives

    • 103 |
    • party_short. The abbreviated name of a party which had elected representatives

    • 104 |
    • seats. The number of seats won by each party

    • 105 |
    • government. Whether or not that party was a part of the government following the election (1, NA)

    • 106 |
    • colour. A hex code indicating the colours of each party

    • 107 |
    108 | 109 |
    110 | 113 |
    114 | 115 | 116 |
    125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | --------------------------------------------------------------------------------