Welcome
Companion Web site
Dedication
1
Introduction
1.1
Why programming?
1.2
Why R?
1.3
Is this book for you?
2
Get Started With R in a Few Easy Steps
2.1
What we’ll cover
2.2
Download R and RStudio
2.3
A brief introduction to RStudio
2.3.1
The console
2.3.2
Other RStudio panes
2.3.3
RStudio Projects
2.4
Try out the console
2.4.1
Create your first object
2.4.2
Data types you’re likely to use often
2.5
Install packages
2.6
Additional infrastructure
2.7
Getting help with packages and functions
2.8
RStudio keyboard shortcuts
2.9
Additional files available online
2.10
Wrap-Up
2.11
Additional resources
3
See How Much You Can Do in a Few Lines of Code
3.1
Packages needed in this chapter
3.2
What we’ll cover
3.3
Simple stock market graphing
3.4
Download and graph a city’s median income
3.5
So many packages!
3.6
Running functions without loading packages
3.7
Comparing one city’s data to the US median
3.8
Run a remote script to make an interactive map
3.9
Bonus map: Mapping income data
3.10
Wrap-Up
3.11
Additional resources
4
Import Data into R
4.1
What we’ll cover
4.2
Packages needed in this chapter
4.3
The magic of rio
4.3.1
Import a file from the Web
4.4
Import data from packages
4.4.1
When the data’s not ideally formatted
4.5
What’s a data frame? And what can you do with one?
4.5.1
When a number’s not really a number
4.6
Easy sample data
4.6.1
Create a data frame manually within R
4.7
Exporting data
4.8
Additional resources
5
Basic Data Exploration
5.1
Project: Weather data
5.2
What we’ll cover
5.3
Packages needed in this chapter
5.4
Download this book’s files
5.5
Data summaries
5.6
Data ‘interviews’
5.7
Slicing and dicing your data set
5.8
More subsetting with dplyr
5.9
Wrap-Up
5.10
Additional resources
6
Beginning data visualization
7
Two or more data sets
8
Analyze data by groups
9
Graphing by Group
10
Write your own R functions
11
Maps in R
12
Putting it all Together: R on Election Day
12.1
Project: Election data
12.2
What we’ll cover
12.3
Packages needed in this chapter
12.4
Election Day preparation
12.4.1
Step 1: Configure data files
12.4.2
Step 2: Load packages
12.4.3
Step 3: Import data.
12.4.4
Step 4: Examine (and wrangle) the data
12.4.5
Step 5: Who won and by how much?
12.4.6
Step 6: Exploratory visualizations
12.5
Visualizing election results
12.6
Graph for a smaller set of results
12.7
plotly
12.8
Other interactive alternatives
12.8.1
taucharts
12.8.2
highcharter
12.8.3
metricsgraphics
12.9
Wrap-up
12.10
(Non-election) inspiration
12.11
Additional resources
13
Date calculations
14
Help! My data’s in the wrong format!
15
Integrate R With Your Storytelling Using R Markdown
16
Simple Web scraping
17
An R project from start to finish
18
Additional resources
Appendix A Online: How do I …
Appendix B Online: Functions
Appendix C Online: Packages
Practical R for Mass Communication and Journalism
4.2
Packages needed in this chapter
rio
htmltab
readxl
googlesheets
pacman
janitor
rmiscutils (GitHub) or readr
tibble