How to Use the fivethirtyeight R Package for Data Analysis

Jan 23, 2022 | Data Science

The fivethirtyeight R package is a treasure trove of data and code sets that showcase the brilliance of data journalism at FiveThirtyEight. This guide will help you discover how to install and use this package effectively, allowing you to leverage its datasets in your analyses.

Getting Started: Installation

Before you can dive into the ocean of data, you need to ensure that you have the fivethirtyeight R package installed. You have two options for installation:

  • To get the latest released version from CRAN, run:
  • install.packages("fivethirtyeight")
  • For the development version from GitHub, you’ll need the remotes package. If you don’t have it yet, you can install it by running:
  • install.packages("remotes")
  • Now install the fivethirtyeight package:
  • remotes::install_github("rudeboybert/fivethirtyeight", build_vignettes = TRUE)

Using the fivethirtyeight Package

Once you have installed the package, using it is a breeze! The datasets are lazy-loaded, which means you can access any dataset without preliminary commands. Here’s how to explore one of the datasets:

library(fivethirtyeight)
head(bechdel)

If you are using RStudio, you can view the dataset interactively by running:

View(bechdel)

There are 128 datasets included in the package. To see a detailed list of these datasets and the corresponding articles published on FiveThirtyEight, click here.

Accessing Additional Datasets

Due to CRAN package size restrictions, there are 19 datasets unavailable in the fivethirtyeight package, but these can be found in the fivethirtyeightdata add-on package. Here’s how to install it:

install.packages("fivethirtyeightdata", repos = "https://fivethirtyeightdata.github.io/drat", type = "source")

To load one of these datasets, like the senators dataset, you can run:

library(fivethirtyeight)
library(fivethirtyeightdata)
senators

Exploring Data Analysis Examples

For some datasets, you can find user-contributed example analyses in the form of package vignettes. An example includes the analysis based on the Bechdel dataset found in the article The Dollar-And-Cents Case Against Hollywood’s Exclusion of Women. To explore user-contributed vignettes, run:

vignette(user_contributed_vignettes, package = "fivethirtyeightdata")

Troubleshooting Tips

If you encounter issues while installing or using the package, here are a few troubleshooting tips:

  • Ensure that R and RStudio are updated to the latest versions.
  • Check if you’ve installed the remotes package if you are trying to install from GitHub.
  • If a dataset fails to load, verify that you used the correct package name and load commands.
  • For any persistent problems, check the GitHub issue page for known issues or to report your own.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Final Thoughts

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox