class: center, middle, inverse, title-slide .title[ # Data Files and Variable Types ] .subtitle[ ## DADM ] .author[ ### Robert W. Walker ] .institute[ ### AGSM/Willamette ] .date[ ### 2020/08/27 (updated: 2023-01-17) ] --- # Data are Ubiquitous We can talk about them in terms of formats and types. **A format describes a machine readable method for storing and transporting data.** Examples include .csv, .tsv, .dta, .xls, .xlsx, .por and many, many others. **A type (or better, a storage type) describes the language of machine readability for any given variable.** Examples include dates and times, numeric [double/float/single], integer, character, factor, logical [TRUE/FALSE], and complex [combining real and imaginary parts]. --- # Formats Proprietary software often has a unique data format. Stata has *.dta* SAS files and SPSS .sav and .por files can be imported. We will work with `.xls` and `.xlsx` formats most. These are Excel's spreadsheet formats. These are not generally human readable. I often use .csv files; these are basic text files where a comma *delimits* -- separates -- cells. These are human readable. **I prefer that in the name of transparency.** --- ## Importing Data The action is here [and it works for both URL and local files]: ![](https://github.com/robertwwalker/DADMStuff/raw/master/ImportFile.png) --- ## Import from Excel ```r library(readxl) url <- "https://github.com/robertwwalker/DADMStuff/raw/master/AnimalCrossing.xlsx" destfile <- "ACrossing.xlsx" curl::curl_download(url, destfile) Critic <- read_excel(destfile, sheet="critic") Items <- read_excel(destfile, sheet="Items") Villagers <- read_excel(destfile, sheet="Villagers") User_reviews <- read_excel(destfile, sheet="User_reviews") ``` Cool. The url for the images are in the data so RMarkdown can access them. ![admiral](https://villagerdb.com/images/villagers/thumb/admiral.98206ee.png) ![angus](https://villagerdb.com/images/villagers/thumb/ankha.8bffa26.png) --- ## Importing from .csv They are text files. Let's actually look at brexit.csv. Three variables: date, percent right, percent wrong. Separated by commas. The comma is the 'delimiter'. ![](https://github.com/robertwwalker/DADMStuff/raw/master/CSV.png) --- # Importing .csv Grab the economist data. ```r brexit <- read.csv("https://github.com/robertwwalker/DADMStuff/raw/master/brexit.csv") corbyn <- read.csv("https://github.com/robertwwalker/DADMStuff/raw/master/corbyn.csv") eu_balance <- read.csv("https://github.com/robertwwalker/DADMStuff/raw/master/eu_balance.csv") pensions <- read.csv("https://github.com/robertwwalker/DADMStuff/raw/master/pensions.csv") dogs <- read.csv("https://github.com/robertwwalker/DADMStuff/raw/master/dogs.csv") trade <- read.csv("https://github.com/robertwwalker/DADMStuff/raw/master/trade.csv") women_research <- read.csv("https://github.com/robertwwalker/DADMStuff/raw/master/women_research.csv") ``` --- # brexit in R ```r brexit ``` <div style="border: 1px solid #ddd; padding: 0px; overflow-y: scroll; height:400px; overflow-x: scroll; width:80%; "><table class="table" style="margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> date </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> percent_responding_right </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> percent_responding_wrong </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 02/08/16 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 09/08/16 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 17/08/16 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 23/08/16 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 31/08/16 </td> <td style="text-align:right;"> 47 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 14/09/16 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 12/10/16 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 20/10/16 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 15/11/16 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 29/11/16 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 05/12/16 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 19/12/16 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 04/01/17 </td> <td style="text-align:right;"> 47 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 10/01/17 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 18/01/17 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 31/01/17 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 13/02/17 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 22/02/17 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 28/02/17 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 14/03/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 15/03/17 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 41 </td> </tr> <tr> <td style="text-align:left;"> 21/03/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 27/03/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 06/04/17 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 13/04/17 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 19/04/17 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 21/04/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 26/04/17 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 03/05/17 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 10/05/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 14/05/17 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 41 </td> </tr> <tr> <td style="text-align:left;"> 17/05/17 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 25/05/17 </td> <td style="text-align:right;"> 46 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 31/05/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 07/06/17 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 13/06/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 22/06/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 11/07/17 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 19/07/17 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 01/08/17 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 22/08/17 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 31/08/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 24/09/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 11/10/17 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 19/10/17 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 20/10/17 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 24/10/17 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 08/11/17 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 05/12/17 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 11/12/17 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 20/12/17 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 08/01/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 17/01/18 </td> <td style="text-align:right;"> 45 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 29/01/18 </td> <td style="text-align:right;"> 40 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 06/02/18 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 13/02/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 20/02/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 27/02/18 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 06/03/18 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 23/03/18 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 48 </td> </tr> <tr> <td style="text-align:left;"> 27/03/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 10/04/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 17/04/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 25/04/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 01/05/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 09/05/18 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 14/05/18 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 21/05/18 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 29/05/18 </td> <td style="text-align:right;"> 40 </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 05/06/18 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 12/06/18 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 19/06/18 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 20/06/18 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 26/06/18 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 04/07/18 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 09/07/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 11/07/18 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 17/07/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 23/07/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 09/08/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 13/08/18 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 14/08/18 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 21/08/18 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 29/08/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 04/09/18 </td> <td style="text-align:right;"> 42 </td> <td style="text-align:right;"> 48 </td> </tr> </tbody> </table></div> --- # Fixing the Dates Dates are difficult. Generically, they need to scale to hours, minutes, seconds, and perhaps worst, time zones. In addition, they can be formatted in myriad ways. ```r brexit <- brexit %>% mutate(date = as.Date(date, format="%d/%m/%y")) # These are dd/mm/yy ``` This is important, particularly if we wish to sequence them according to time, and we do when we visualize them. --- # To Esquisse I will need to reorganize the data; I need to make it `tidy`. This is known as **pivoting**. ```r brexitL <- brexit %>% pivot_longer(., c(percent_responding_right,percent_responding_wrong), names_to = "Choice", values_to="Percent") ``` <div style="border: 1px solid #ddd; padding: 0px; overflow-y: scroll; height:400px; "><table class="table" style="margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> date </th> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Choice </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Percent </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 2016-08-02 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2016-08-02 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2016-08-09 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2016-08-09 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2016-08-17 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2016-08-17 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2016-08-23 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2016-08-23 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2016-08-31 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 2016-08-31 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2016-09-14 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2016-09-14 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2016-10-12 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2016-10-12 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2016-10-20 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2016-10-20 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2016-11-15 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2016-11-15 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2016-11-29 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2016-11-29 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2016-12-05 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2016-12-05 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2016-12-19 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2016-12-19 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-01-04 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 2017-01-04 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-01-10 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-01-10 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-01-18 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-01-18 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-01-31 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-01-31 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-02-13 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-02-13 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-02-22 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-02-22 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-02-28 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-02-28 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-03-14 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-03-14 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-03-15 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-03-15 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 41 </td> </tr> <tr> <td style="text-align:left;"> 2017-03-21 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-03-21 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-03-27 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-03-27 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-06 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-06 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-13 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-13 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-19 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-19 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-21 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-21 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-26 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-04-26 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-03 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-03 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-10 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-10 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-14 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-14 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 41 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-17 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-17 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-25 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-25 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-31 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-05-31 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-06-07 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-06-07 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-06-13 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-06-13 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-06-22 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-06-22 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-07-11 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-07-11 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-07-19 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-07-19 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-08-01 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-08-01 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-08-22 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-08-22 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-08-31 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-08-31 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-09-24 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-09-24 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-10-11 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-10-11 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 2017-10-19 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-10-19 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-10-20 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-10-20 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-10-24 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2017-10-24 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-11-08 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-11-08 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2017-12-05 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-12-05 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-12-11 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2017-12-11 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2017-12-20 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2017-12-20 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-01-08 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-01-08 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-01-17 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-01-17 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-01-29 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 40 </td> </tr> <tr> <td style="text-align:left;"> 2018-01-29 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-02-06 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2018-02-06 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-02-13 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-02-13 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-02-20 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-02-20 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-02-27 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-02-27 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-03-06 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2018-03-06 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-03-23 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-03-23 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 48 </td> </tr> <tr> <td style="text-align:left;"> 2018-03-27 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-03-27 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-04-10 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-04-10 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-04-17 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-04-17 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-04-25 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-04-25 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-01 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-01 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-09 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-09 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-14 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-14 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-21 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-21 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-29 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 40 </td> </tr> <tr> <td style="text-align:left;"> 2018-05-29 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-05 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-05 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-12 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-12 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-19 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-19 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-20 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 44 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-20 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-26 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2018-06-26 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-04 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 41 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-04 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-09 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-09 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-11 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 41 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-11 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-17 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-17 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-23 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-07-23 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 46 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-09 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-09 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-13 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-13 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-14 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 43 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-14 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 45 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-21 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 41 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-21 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-29 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-08-29 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 47 </td> </tr> <tr> <td style="text-align:left;"> 2018-09-04 </td> <td style="text-align:left;"> percent_responding_right </td> <td style="text-align:right;"> 42 </td> </tr> <tr> <td style="text-align:left;"> 2018-09-04 </td> <td style="text-align:left;"> percent_responding_wrong </td> <td style="text-align:right;"> 48 </td> </tr> </tbody> </table></div> --- # A Plot ```r ggplot(brexitL) + aes(x = date, y = Percent, colour = Choice) + geom_line(linewidth = 1L) + geom_point() + scale_color_viridis_d(option = "cividis") + ggthemes::theme_tufte() + labs(title="Brexit: Right or Wrong?") ``` --- ![](index_files/figure-html/unnamed-chunk-8-1.png)<!-- --> --- # Better ```r ggplot(brexitL) + aes(x = date, y = Percent, colour = Choice) + geom_smooth() + geom_point() + scale_color_viridis_d(option = "cividis") + ggthemes::theme_tufte() + labs(title="Brexit: Right or Wrong?") ``` --- ![](index_files/figure-html/unnamed-chunk-10-1.png)<!-- --> --- # Pensions ```r ggplot(pensions) + aes(x = pop_65_percent, y = gov_spend_percent_gdp) + geom_point(size = 1L, colour = "#0c4c8a") + labs(x = "Population 65+ ", y = "Government Spending to GDP") + theme_minimal() ``` --- ![](index_files/figure-html/unnamed-chunk-12-1.png)<!-- --> --- # Better [label and geom_text] ```r ggplot(pensions) + aes(x = pop_65_percent, y = gov_spend_percent_gdp, label = country) + geom_text() + labs(x = "Population 65+ ", y = "Government Spending to GDP") + theme_minimal() ``` --- # Better [label and geom_text] ![](index_files/figure-html/unnamed-chunk-14-1.png)<!-- --> --- # Best [label and geom_label_repel] ![](index_files/figure-html/unnamed-chunk-15-1.png)<!-- -->