{"id":16284675,"url":"https://github.com/pachadotdev/spuriouscorrelations","last_synced_at":"2025-10-18T20:37:44.041Z","repository":{"id":199312062,"uuid":"702612876","full_name":"pachadotdev/spuriouscorrelations","owner":"pachadotdev","description":"Keeping alive the amazing examples from Tyler Vigen","archived":false,"fork":false,"pushed_at":"2023-10-10T14:50:10.000Z","size":570,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T22:41:06.413Z","etag":null,"topics":["correlation","r"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pachadotdev.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-09T16:39:01.000Z","updated_at":"2023-10-16T13:54:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"a5725626-8fb3-41f0-8520-54380f82a0af","html_url":"https://github.com/pachadotdev/spuriouscorrelations","commit_stats":null,"previous_names":["pachadotdev/spuriouscorrelations"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fspuriouscorrelations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fspuriouscorrelations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fspuriouscorrelations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fspuriouscorrelations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pachadotdev","download_url":"https://codeload.github.com/pachadotdev/spuriouscorrelations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244041579,"owners_count":20388265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["correlation","r"],"created_at":"2024-10-10T19:20:24.822Z","updated_at":"2025-10-18T20:37:43.936Z","avatar_url":"https://github.com/pachadotdev.png","language":"HTML","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# Spurious correlations \u003cimg src=\"man/figures/logo.svg\" align=\"right\" height=\"139\" alt=\"\" /\u003e\n\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\nThe goal of spuriouscorrelations is to keep alive the amazing examples from\n[Tyler Vigen](https://web.archive.org/web/20230607181247/https://tylervigen.com/spurious-correlations).\nUnfortunately, as of 2023-10-09, the website is down as my students noticed.\nTherefore, I decided to use the snapshot from the Internet Wayback Machine to\nsave the datasets from 2023-06-07.\n\n## Installation\n\nYou can install the development version of spuriouscorrelations like so:\n\n``` r\nremotes::install_github(\"pachadotdev/spuriouscorrelations\")\n```\n\n## Example\n\nThis is a basic example which shows you how to plot a spurious correlation:\n\n```{r example}\nlibrary(dplyr)\nlibrary(ggplot2)\nlibrary(spuriouscorrelations)\n\nunique(spurious_correlations$var2_short)\n\nnicholas_cage \u003c- spurious_correlations %\u003e%\n  filter(var2_short == \"Nicholas Cage\")\n\nggplot(nicholas_cage) +\n  geom_point(aes(x = var1_value, y = var2_value, color = year), size = 4) +\n  theme_minimal() +\n  labs(\n    x = \"Drownings by falling into a pool\",\n    y = \"Nicholas Cage movies\",\n    title = \"Drownings by Falling into a Pool vs Nicholas Cage Movies\"\n  )\n```\n\nThe correlation is:\n```{r example2}\ncor(nicholas_cage$var1_value, nicholas_cage$var2_value)\n```\n\nNow let's make it double-axis:\n  \n```{r example3}\nlibrary(tidyr)\n\nnicholas_cage_long \u003c- nicholas_cage %\u003e%\n  select(year, var1_value, var2_value) %\u003e%\n  pivot_longer(\n    cols = c(var1_value, var2_value),\n    names_to = \"variable\",\n    values_to = \"value\"\n  ) %\u003e%\n  # standardize the values\n  group_by(variable) %\u003e%\n  mutate(\n    value = (value - mean(value)) / sd(value),\n    variable = case_when(\n      variable == \"var1_value\" ~ \"Drownings by falling into a pool\",\n      variable == \"var2_value\" ~ \"Nicholas Cage movies\"\n    )\n  )\n\n# make a double y axis plot with year on the x axis\nggplot(nicholas_cage_long, aes(\n  x = year, y = value, color = variable,\n  group = variable\n)) +\n  geom_line() +\n  geom_point() +\n  theme_minimal() +\n  theme(legend.position = \"top\") +\n  labs(\n    x = \"Year\",\n    y = \"Standardized values\",\n    title = \"Drownings by Falling into a Pool vs Nicholas Cage Movies\"\n  )\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpachadotdev%2Fspuriouscorrelations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpachadotdev%2Fspuriouscorrelations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpachadotdev%2Fspuriouscorrelations/lists"}