R for the Rest of Us: A Statistics-Free Introduction 9781718503335, 9781718503328

The R programming language is a remarkably powerful tool for data analysis and visualization, but its steep learning cur

126 68 19MB

English Pages 256 Year 2024

Report DMCA / Copyright

DOWNLOAD EPUB FILE

Table of contents :
Cover
Praise for R for the Rest of Us
Title Page
Copyright
Dedication
About the Author and Technical Reviewer
Acknowledgments
Introduction
Isn’t R Just for Statistical Analysis?
Who This Book Is For
About This Book
Part I: Visualizations
1. An R Programming Crash Course
Setting Up
Installing R and RStudio
Exploring the RStudio Interface
R Script Files
Basic R Syntax
Arithmetic Operators
Comparison Operators
Functions
Working with Data
Importing Data
Saving Data as Objects
Installing Packages
RStudio Projects
Data Analysis with the tidyverse
tidyverse Functions
The tidyverse Pipe
Comments
How to Get Help
Summary
Additional Resources
2. Principles of Data Visualization
The Drought Visualization
The Grammar of Graphics
Working with ggplot
Mapping Data to Aesthetic Properties
Choosing the Geometric Objects
Altering Aesthetic Properties
Setting a Theme
Re-creating the Drought Visualization
Plotting One Region and Year
Changing Aesthetic Properties
Faceting the Plot
Adding Final Polishes
The Complete Visualization Code
Summary
Additional Resources
3. Custom Data Visualization Themes
Styling a Plot with a Custom Theme
An Example Plot
The BBC’s Custom Theme
The BBC Theme Components
Function Definition
Text
Legend
Axes
Grid Lines
Background
Small Multiples
Color
Summary
Additional Resources
4. Maps and Geospatial Data
A Brief Primer on Geospatial Data
The Geometry Type
The Dimensions
The Bounding Box
The Coordinate Reference System
The geometry Column
Re-creating the COVID-19 Map
Importing the Data
Calculating Daily COVID-19 Cases
Calculating Incidence Rates
Adding Geospatial Data
Making the Map
Making Your Own Maps
Importing Raw Data
Accessing Geospatial Data with R Functions
Using Appropriate Projections
Wrangling Geospatial Data
Summary
Additional Resources
5. Designing Effective Tables
Creating a Data Frame
Table Design Principles
Minimize Clutter
Differentiate the Header from the Body
Align Appropriately
Use the Correct Level of Precision
Use Color Intentionally
Add a Data Visualization Where Appropriate
Summary
Additional Resources
Part II: Reports, Presentations, and Websites
6. R Markdown Reports
Creating an R Markdown Document
Document Structure
The YAML Metadata
The R Code Chunks
Markdown Text
Inline R Code
Running Code Chunks Interactively
Quarto
Summary
Additional Resources
7. Parameterized Reporting
Report Templates in R Markdown
Defining Parameters
Generating Numbers with Parameters
Including Parameters in Visualization Code
Creating an R Script
Knitting the Document with Code
Creating a Tibble with Parameter Data
Best Practices
Summary
Additional Resources
8. Slideshow Presentations
Why Use xaringan?
How xaringan Works
Creating a New Slide
Adjusting the Size of Figures
Revealing Content Incrementally
Aligning Content with Content Classes
Adding Background Images to Slides
Applying CSS to Slides
Custom CSS
Themes
The xaringanthemer Package
Summary
Additional Resources
9. Websites
Creating a New distill Project
The Project Files
R Markdown Documents
The _site.yml File
Building the Site
Applying Custom CSS
Working with Website Content
Applying distill Layouts
Making the Content Interactive
Hosting the Website
Cloud Hosting
GitHub Hosting
Summary
Additional Resources
10. Quarto
Creating a Quarto Document
Comparing R Markdown and Quarto
The format and execute YAML Fields
Individual Code Chunk Options
Dashes in Option Names
The Render Button
Parameterized Reporting
Making Presentations
Revealing Content Incrementally
Aligning Content and Adding Background Images
Customizing Your Slides with Themes and CSS
Making Websites
Building the Website
Setting Options
Changing the Website’s Appearance
Adjusting the Title and Navigation Bar
Creating Wider Layouts
Hosting Your Website on GitHub Pages and Quarto Pub
Summary
Additional Resources
Part III: Automation and Collaboration
11. Automatically Accessing Online Data
Importing Data from Google Sheets with googlesheets4
Connecting to Google
Reading Data from a Sheet
Using the Data in R Markdown
Importing Only Certain Columns
Accessing Census Data with tidycensus
Connecting to the Census Bureau with an API Key
Working with Decennial Census Data
Identifying Census Variable Values
Using Multiple Census Variables
Analyzing Census Data
Using a Summary Variable
Visualizing American Community Survey Data
Making Charts
Making Population Maps with the geometry Argument
Summary
Additional Resources
12. Creating Functions and Packages
Creating Your Own Functions
Writing a Simple Function
Adding Arguments
Creating a Function to Format Race and Ethnicity Data
Using … to Pass Arguments to Another Function
Creating a Package
Starting the Package
Adding Functions with use_r()
Checking the Package with devtools
Adding Dependency Packages
Referring to Functions Correctly
Creating Documentation with Roxygen
Adding a License and Metadata
Writing Additional Functions
Installing the Package
Summary
Additional Resources
Wrapping Up
Index

R for the Rest of Us: A Statistics-Free Introduction
 9781718503335, 9781718503328

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
Recommend Papers