PrefaceAbout the authorI Introduction1 A soup to nuts project example1.1 Big picture data example1.2 Little picture data example1.2.1 Loading packages1.2.2 Loading data1.2.3 Cleaning1.2.4 Aggregating1.2.5 Graphing1.3 Reusing and modifying code2 Introduction to R and RStudio2.1 Using RStudio2.1.1 Opening an R Script2.1.2 Setting the working directory2.1.3 Changing RStudio2.1.4 Helpful cheat sheets2.2 Assigning variables2.3 What are functions (and packages)?2.4 Reading data into R2.4.1 Loading data2.5 First steps to exploring data3 Data types and structures3.1 Data types3.2 Numeric, character, and logical (boolean)3.3 Data structures3.3.1 Vectors (collections of "things")3.3.2 Data.frames3.3.3 Other data structures4 Reading and writing data4.1 Reading data into R4.1.1 R4.1.2 Excel4.1.3 Stata4.1.4 SAS4.1.5 SPSS4.1.6 Fixed-width ASCII4.2 Writing data4.2.1 R4.2.2 Excel4.2.3 Stata4.2.4 SAS4.2.5 SPSSII Project Management5 Mise en place5.1 Starting with a pencil and paper5.1.1 Tables and graphs5.2 R Projects5.2.1 Folders5.3 Modular R scripts5.4 Modular code5.4.1 Section labels5.4.2 Helper R scripts6 Collaboration6.1 Code review6.1.1 Style guidelines6.2 Documentation6.2.1 Comments6.2.2 Vignettes7 R Markdown7.1 Code7.1.1 Hiding code in the output7.2 Inline Code7.3 Tables7.4 Footnotes7.5 Citation7.6 Spell check7.7 Making the output file8 Testing your code8.1 Why test your code?8.2 Unit tests8.2.1 Modular test scripts8.2.2 How to write unit tests8.2.3 What to test8.3 Test-driven development (TDD)9 Git9.1 What is Git, and why do I need it?9.2 Git basics9.3 Using Git9.3.1 Setting up Git9.3.2 Setting up GitHub9.4 Setting up Git on an already-made R Project9.5 Using Git through RStudio9.6 When to commit9.7 Other resourcesIII Clean10 Subsetting: Making big things small10.1 Select specific values10.2 Logical values and operations10.2.1 Matching a single value10.2.2 Matching multiple values10.2.3 Does not match10.2.4 Greater than or less than10.2.5 Combining conditional statements - or, and10.3 Subsetting a data.frame10.3.1 Select specific columns10.3.2 Select specific rows10.3.3 Subset Colorado data11 Exploratory data analysis11.1 Summary and Table11.2 Graphing11.3 Aggregating (summaries of groups)11.4 Pipes in dpiyr12 Regular Expressions12.1 Finding patterns in text with grep()12.2 Finding and replacing patterns in text with gsub()12.3 Useful special characters12.3.1 Multiple characters [ ]12.3.2 n-many of previous character {n}12.3.3 n-many to m-many of previous character {n,m}12.3.4 Start of string12.3.5 End of string $12.3.6 Anything12.3.7 One or more of previous12.3.8 Zero or more of previous12.3.9 Multiple patterns12.3.10 Parentheses ()12.3.11 Optional text?12.4 Changing capitalization13 Reshaping data13.1 Reshaping a single column13.2 Reshaping multiple columnsIV Visualize14 Graphing with ggpiot214.1 What does the data look like?14.2 Graphing data14.3 Time-series plots14.4 Scatter plots14.5 Color blindness15 More graphing with ggptot215.1 Exploring data15.2 Graphing a single numeric variable15.2.1 Histogram15.2.2 Density plot15.2.3 Count graph15.3 Graphing a categorical variable15.3.1 Bar graph15.4 Graphing data over time15.5 Pretty graphs15.5.1 Themes16 Hotspot maps16.1 A simple map16.2 What really are maps?16.3 Making a hotspot map16.3.1 Colors17 Choropleth maps17.1 Spatial joins17.2 Making choropleth maps18 Interactive maps18.1 Why do interactive graphs matter?18.1.1 Understanding your data18.1.2 Police departments use them18.2 Making the interactive map18.3 Adding popup information18.4 Dealing with too many markers18.5 Interactive choropleth mapsV Collect19 Webscraping with $$19.1 Scraping one page19.2 Cleaning the webscraped data20 Functions20.1 A simple function20.2 Adding parameters20.3 Making a function to scrape recipes21 For loops21.1 Basic for loops21.2 Scraping multiple recipes22 Scraping tables from PDFs22.1 Scraping the first table22.2 Making a function23 More scraping tables from PDFs23.1 Texas jail data23.2 Pregnant women incarcerated23.3 Making PDF-scraped data available to others24 Geocoding24.1 Geocoding a single address24.2 Geocoding San Francisco marijuana dispensary locationsBibliography