The goal of pollsDK is to make it easy to download and use danish polling data.
You can install pollsDK from github with:
# install.packages("devtools")
devtools::install_github("mikkelkrogsholm/pollsDK")
library(pollsDK); library(tidyverse)
The package owes a lot to Erik Gahner whos github repo polls is a plethora of polling data.
get_gahner()
## Collects poll data from Erik Gahners Github
g <- get_gahner()
glimpse(g)
#> Observations: 1,123
#> Variables: 18
#> $ id <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,...
#> $ pollingfirm <chr> "Megafon", "Gallup", "Greens", "Rambøll", "Megafo...
#> $ year <int> 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 20...
#> $ month <int> 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5,...
#> $ day <int> 20, 29, 3, 11, 25, 26, 3, 4, 24, 26, 30, 12, 14, 2...
#> $ party_a <dbl> 25.4, 25.0, 26.2, 26.6, 25.8, 26.6, 28.4, 24.6, 25...
#> $ party_b <dbl> 4.5, 3.4, 5.4, 4.1, 4.4, 4.7, 5.0, 4.7, 5.1, 4.3, ...
#> $ party_c <dbl> 11.2, 11.1, 9.6, 9.7, 11.4, 10.4, 11.0, 12.7, 11.2...
#> $ party_d <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#> $ party_f <dbl> 18.5, 19.1, 16.9, 18.3, 16.8, 16.4, 14.7, 16.9, 18...
#> $ party_i <dbl> 0.3, 0.7, 1.1, 0.5, 0.6, 0.4, 0.4, 0.2, 1.2, 0.8, ...
#> $ party_k <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#> $ party_o <dbl> 14.6, 14.2, 14.2, 13.7, 15.2, 13.7, 11.7, 12.6, 13...
#> $ party_v <dbl> 22.4, 23.7, 24.0, 23.7, 22.2, 24.9, 25.5, 24.6, 22...
#> $ party_oe <dbl> 2.6, 2.2, 2.1, 2.5, 3.1, 2.3, 2.7, 3.0, 2.5, 2.4, ...
#> $ party_aa <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
#> $ n <int> 1089, 1450, 1050, 1050, 1000, 1450, 1050, NA, 1089...
#> $ source <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA...
You can also pull the polls from Berlingske Barometer and Ritzau Index
get_berlingske()
# Get the Berlingske Barometer
b <- get_berlingske()
glimpse(b)
#> Observations: 748
#> Variables: 6
#> $ letter <chr> "A", "Å", "B", "C", "D", "F", "I", "K", "O", "Ø", ...
#> $ percent <dbl> 26.9, 5.8, 5.7, 3.9, 2.5, 4.9, 6.4, 0.6, 16.8, 8.0...
#> $ mandates <dbl> 47, 10, 10, 7, 4, 9, 11, 0, 30, 14, 33, 48, 10, 9,...
#> $ support <dbl> 2, 2, 2, 1, 1, 2, 1, 1, 1, 2, 9, 2, 2, 2, 1, 1, 2,...
#> $ uncertainty <dbl> 1.4, 0.7, 0.7, 0.6, 0.5, 0.7, 0.8, 0.2, 1.2, 0.8, ...
#> $ datetime <dttm> 2017-01-05, 2017-01-05, 2017-01-05, 2017-01-05, 2...
get_polls()
# Get polls from Berlingske
p <- get_polls()
glimpse(p)
#> Observations: 835
#> Variables: 9
#> $ letter <chr> "A", "Å", "B", "C", "D", "F", "I", "K", "O", "Ø", ...
#> $ percent <dbl> 25.9, 5.0, 5.7, 3.6, 2.6, 5.4, 5.6, 0.6, 17.8, 7.4...
#> $ mandates <dbl> 46, 9, 10, 6, 5, 10, 10, 0, 31, 13, 35, 49, 11, 8,...
#> $ support <dbl> 2, 2, 2, 1, 1, 2, 1, 1, 1, 2, 9, 2, 2, 2, 1, 1, 2,...
#> $ uncertainty <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...
#> $ pollster <chr> "Gallup", "Gallup", "Gallup", "Gallup", "Gallup", ...
#> $ description <chr> "Gallup Politisk Indeks er baseret på 1.522 telefo...
#> $ respondents <dbl> 1522, 1522, 1522, 1522, 1522, 1522, 1522, 1522, 15...
#> $ datetime <dttm> 2017-01-05, 2017-01-05, 2017-01-05, 2017-01-05, 2...
For both get_polls()
and get_berlingske()
it will pull polls from the current year. You can change that by supplying it with the year argument.
# And even from previous years
p14 <- get_polls(2014)
glimpse(p14)
#> Observations: 1,017
#> Variables: 9
#> $ letter <chr> "A", "A", "B", "B", "C", "C", "F", "F", "I", "I", ...
#> $ percent <dbl> 23.8, 21.8, 8.4, 8.4, 3.6, 4.2, 3.9, 4.2, 4.8, 4.0...
#> $ mandates <dbl> 42, 39, 15, 15, 6, 7, 7, 8, 8, 7, 0, 0, 29, 32, 20...
#> $ support <dbl> 9, 9, 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 2,...
#> $ uncertainty <dbl> 2.1, 2.3, 1.4, 1.6, 0.9, 1.1, 1.0, 1.1, 1.1, 1.1, ...
#> $ pollster <chr> "Gallup", "Greens", "Gallup", "Greens", "Gallup", ...
#> $ description <chr> "Gallup Politisk Indeks er baseret på 1.579 telefo...
#> $ respondents <dbl> 1579, 1199, 1579, 1199, 1579, 1199, 1579, 1199, 15...
#> $ datetime <dttm> 2014-01-09, 2014-01-09, 2014-01-09, 2014-01-09, 2...
get_ritzau()
Ritzau provides a list of data frame with the most recent polls from a select number of pollsters. Each one hase the pollsters number and Ritzaus own index.
# Get Ritzau data
r <- get_ritzau()
#> List with data frames of polls:
#>
#> Each data frame include the Ritzau Index
glimpse(r[[1]])
#> Observations: 12
#> Variables: 13
#> $ PartyId <int> 1, 4, 2, 8, 11, 10, 9, 3, 7, 6, 5, 17
#> $ Party <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
#> $ PartyName <chr> "A - Socialdemokraterne", "F - Socialistisk F...
#> $ PartyLogo <chr> "a.png", "f.png", "b.png", "o.png", "alt.png"...
#> $ PartyBlock <chr> "R", "R", "R", "R", "R", "O", "B", "B", "B", ...
#> $ PartyColor <chr> "#b1161c", "#df2027", "#d13076", "#71b75b", "...
#> $ Percentage <dbl> 26.3, 4.6, 6.2, 8.0, 5.2, 0.5, 17.5, 4.8, 18....
#> $ Mandate <dbl> 47, 8, 11, 14, 9, 0, 32, 9, 33, 12, 0, 0
#> $ RitzauPartyColor <chr> "#e4d9d9", "#d5bfbf", "#d2bfc6", "#d1d8cf", "...
#> $ RitzauPercentage <dbl> 26.23, 4.87, 5.68, 8.55, 5.18, 0.30, 18.70, 4...
#> $ RitzauMandate <dbl> 47, 9, 10, 15, 9, 0, 34, 7, 33, 11, 0, 0
#> $ ChartSortOrder <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 105
#> $ IsOfficial <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRU...
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.