• Stars
    star
    758
  • Rank 59,918 (Top 2 %)
  • Language
    R
  • License
    Creative Commons ...
  • Created over 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿคนโ€โ™€ Animations of tidyverse verbs using R, the tidyverse, and gganimate

Tidy Animated Verbs

CC0 MIT

Garrick Aden-Buie โ€“ @grrrck โ€“ garrickadenbuie.com

Thanks to contributions from โ€ฆ

Animations:

Background

Usage

Please feel free to use these images for teaching or learning about action verbs from the tidyverse. You can directly download the original animations or static images in svg or png formats, or you can use the scripts to recreate the images locally.

Currently, the animations cover the dplyr two-table verbs and Iโ€™d like to expand the animations to include more verbs from the tidyverse. Suggestions are welcome!

Relational Data

The Relational Data chapter of the R for Data Science book by Garrett Grolemund and Hadley Wickham is an excellent resource for learning more about relational data.

The dplyr two-table verbs vignette and Jenny Bryanโ€™s Cheatsheet for dplyr join functions are also great resources.

gganimate

The animations were made possible by the newly re-written gganimate package by Thomas Lin Pedersen (original by Dave Robinson). The package readme provides an excellent (and quick) introduction to gganimate.

Dynamic Animations

Thanks to an initial push by David Zimmermann, we have begun work towards functions that generate dynamic animations from usersโ€™ actual data. Please visit the pkg branch of the tidyexplain repository for more information (or to contribute!).

Mutating Joins

A mutating join allows you to combine variables from two tables. It first matches observations by their keys, then copies across variables from one table to the other.
R for Data Science: Mutating joins

x
#> # A tibble: 3 ร— 2
#>      id x    
#>   <int> <chr>
#> 1     1 x1   
#> 2     2 x2   
#> 3     3 x3
y
#> # A tibble: 3 ร— 2
#>      id y    
#>   <int> <chr>
#> 1     1 y1   
#> 2     2 y2   
#> 3     4 y4

Inner Join

All rows from x where there are matching values in y, and all columns from x and y.

inner_join(x, y, by = "id")
#> # A tibble: 2 ร— 3
#>      id x     y    
#>   <int> <chr> <chr>
#> 1     1 x1    y1   
#> 2     2 x2    y2

Left Join

All rows from x, and all columns from x and y. Rows in x with no match in y will have NA values in the new columns.

left_join(x, y, by = "id")
#> # A tibble: 3 ร— 3
#>      id x     y    
#>   <int> <chr> <chr>
#> 1     1 x1    y1   
#> 2     2 x2    y2   
#> 3     3 x3    <NA>

Left Join (Extra Rows in y)

โ€ฆ If there are multiple matches between x and y, all combinations of the matches are returned.

y_extra # has multiple rows with the key from `x`
#> # A tibble: 4 ร— 2
#>      id y    
#>   <dbl> <chr>
#> 1     1 y1   
#> 2     2 y2   
#> 3     4 y4   
#> 4     2 y5
left_join(x, y_extra, by = "id")
#> # A tibble: 4 ร— 3
#>      id x     y    
#>   <dbl> <chr> <chr>
#> 1     1 x1    y1   
#> 2     2 x2    y2   
#> 3     2 x2    y5   
#> 4     3 x3    <NA>

Right Join

All rows from y, and all columns from x and y. Rows in y with no match in x will have NA values in the new columns.

right_join(x, y, by = "id")
#> # A tibble: 3 ร— 3
#>      id x     y    
#>   <int> <chr> <chr>
#> 1     1 x1    y1   
#> 2     2 x2    y2   
#> 3     4 <NA>  y4

Full Join

All rows and all columns from both x and y. Where there are not matching values, returns NA for the one missing.

full_join(x, y, by = "id")
#> # A tibble: 4 ร— 3
#>      id x     y    
#>   <int> <chr> <chr>
#> 1     1 x1    y1   
#> 2     2 x2    y2   
#> 3     3 x3    <NA> 
#> 4     4 <NA>  y4

Filtering Joins

Filtering joins match observations in the same way as mutating joins, but affect the observations, not the variables. โ€ฆ Semi-joins are useful for matching filtered summary tables back to the original rows. โ€ฆ Anti-joins are useful for diagnosing join mismatches.
R for Data Science: Filtering Joins

Semi Join

All rows from x where there are matching values in y, keeping just columns from x.

semi_join(x, y, by = "id")
#> # A tibble: 2 ร— 2
#>      id x    
#>   <int> <chr>
#> 1     1 x1   
#> 2     2 x2

Anti Join

All rows from x where there are not matching values in y, keeping just columns from x.

anti_join(x, y, by = "id")
#> # A tibble: 1 ร— 2
#>      id x    
#>   <int> <chr>
#> 1     3 x3

Set Operations

Set operations are occasionally useful when you want to break a single complex filter into simpler pieces. All these operations work with a complete row, comparing the values of every variable. These expect the x and y inputs to have the same variables, and treat the observations like sets.
R for Data Science: Set operations

x
#> # A tibble: 3 ร— 2
#>   x     y    
#>   <chr> <chr>
#> 1 1     a    
#> 2 1     b    
#> 3 2     a
y 
#> # A tibble: 2 ร— 2
#>   x     y    
#>   <chr> <chr>
#> 1 1     a    
#> 2 2     b

Union

All unique rows from x and y.

union(x, y)
#> # A tibble: 4 ร— 2
#>   x     y    
#>   <chr> <chr>
#> 1 1     a    
#> 2 1     b    
#> 3 2     a    
#> 4 2     b

union(y, x)
#> # A tibble: 4 ร— 2
#>   x     y    
#>   <chr> <chr>
#> 1 1     a    
#> 2 2     b    
#> 3 1     b    
#> 4 2     a

Union All

All rows from x and y, keeping duplicates.

union_all(x, y)
#> # A tibble: 5 ร— 2
#>   x     y    
#>   <chr> <chr>
#> 1 1     a    
#> 2 1     b    
#> 3 2     a    
#> 4 1     a    
#> 5 2     b

Intersection

Common rows in both x and y, keeping just unique rows.

intersect(x, y)
#> # A tibble: 1 ร— 2
#>   x     y    
#>   <chr> <chr>
#> 1 1     a

Set Difference

All rows from x which are not also rows in y, keeping just unique rows.

setdiff(x, y)
#> # A tibble: 2 ร— 2
#>   x     y    
#>   <chr> <chr>
#> 1 1     b    
#> 2 2     a

setdiff(y, x)
#> # A tibble: 1 ร— 2
#>   x     y    
#>   <chr> <chr>
#> 1 2     b

Tidy Data

Tidy data follows the following three rules:

  1. Each variable has its own column.
  2. Each observation has its own row.
  3. Each value has its own cell.

Many of the tools in the tidyverse expect data to be formatted as a tidy dataset and the tidyr package provides functions to help you organize your data into tidy data.

wide
#> # A tibble: 2 ร— 4
#>      id x     y     z    
#>   <int> <chr> <chr> <chr>
#> 1     1 a     c     e    
#> 2     2 b     d     f
long
#> # A tibble: 6 ร— 3
#>      id key   val  
#>   <int> <chr> <chr>
#> 1     1 x     a    
#> 2     2 x     b    
#> 3     1 y     c    
#> 4     2 y     d    
#> 5     1 z     e    
#> 6     2 z     f

Pivot Wider and Longer

pivot_wider() and pivot_longer() were introduced in tidyr version 1.0 (released in September 2019). They provide a more consistent and more powerful approach to changing the fundamental shape of the data and are โ€œmodern alternatives to spread() and gather().

Here we show the very basic mechanics of pivoting, but thereโ€™s much more that the pivot functions can do. You can learn more about them in the Pivoting vignette in tidyr.

pivot_wider(data, names_from = key, values_from = val)

pivot_wider() โ€œwidensโ€ data, increasing the number of columns and decreasing the number of rows.

pivot_longer(data, cols = x:y, names_to = "key", values_to = "val")

pivot_longer() โ€œlengthensโ€ data, increasing the number of rows and decreasing the number of columns.

Spread and Gather

spread(data, key, value)

Spread a key-value pair across multiple columns. Use it when an a column contains observations from multiple variables.

gather(data, key = "key", value = "value", ...)

Gather takes multiple columns and collapses into key-value pairs, duplicating all other columns as needed. You use gather() when you notice that your column names are not names of variables, but values of a variable.

gather(wide, key, val, x:z)
#> # A tibble: 6 ร— 3
#>      id key   val  
#>   <int> <chr> <chr>
#> 1     1 x     a    
#> 2     2 x     b    
#> 3     1 y     c    
#> 4     2 y     d    
#> 5     1 z     e    
#> 6     2 z     f
spread(long, key, val)
#> # A tibble: 2 ร— 4
#>      id x     y     z    
#>   <int> <chr> <chr> <chr>
#> 1     1 a     c     e    
#> 2     2 b     d     f

More Repositories

1

rsthemes

๐Ÿ”ฎ Full RStudio IDE and Syntax Themes
SCSS
504
star
2

regexplain

๐Ÿ” An RStudio addin slash regex utility belt
R
476
star
3

xaringanthemer

๐Ÿ˜Ž Give your xaringan slides some style
R
437
star
4

xaringanExtra

๐ŸŽก A playground of enhancements and extensions for xaringan slides.
JavaScript
433
star
5

ggpomological

๐Ÿ‘ Pomological plot theme for ggplot2
R
325
star
6

countdown

โฒ countdown timer for R Markdown slides and HTML docs
JavaScript
148
star
7

epoxy

Extra-strength glue engines for R Markdown and Quarto
R
146
star
8

cleanrmd

๐Ÿ“„โœจClean Class-Less R Markdown HTML Documents
CSS
128
star
9

tweet-conf-dash

A shiny twitter conference dashboard
CSS
121
star
10

shrtcts

Make Anything an RStudio Shortcut
R
103
star
11

ggweekly

๐Ÿ—“ ๐Ÿ–จ Easy, printable, custom calendars and week planners
R
101
star
12

tweetrmd

Embed Tweets in R Markdown
R
101
star
13

gentle-ggplot2

๐Ÿ“Š A Gentle Guide to the Grammar of Graphics with ggplot2
HTML
83
star
14

grkstyle

A Tidy R Code Style
R
81
star
15

metathis

โ„น๏ธ <meta> tags and social media cards for R-made web things
R
62
star
16

js4shiny

Companion Package for JavaScript for Shiny Users
R
53
star
17

mueller-report

The โ–ˆโ–ˆredacted Mueller Report
R
47
star
18

shinyComponents

๐Ÿ“โœจ Shiny Components in R Markdown
R
44
star
19

trump-tweet-time

๐ŸŽฎ An 8-bit Trump tweet guessing game for your "executive time"
R
36
star
20

starwarsdb

Relational Data from the Star Wars API for Learning and Teaching
R
35
star
21

covid19-florida

Florida COVID19 Data parsed from Florida DOH Dashboard and PDF reports
HTML
32
star
22

rsconf_tweets

rstudio::conf 2018 tweet explorer and FOMO reducer
R
30
star
23

status

HTML
29
star
24

ermoji

๐Ÿคทโ€โ™‚๏ธ RStudio Addin to Search and Copy Emoji
R
26
star
25

lorem

Generate Lorem Ipsum Text
R
26
star
26

shinyThings

Reusable Shiny Modules and Other Shiny Things
R
25
star
27

trug-ggplot2

๐Ÿ“Š Slides for presentation on ggplot2 at Tampa R Users Meetup (Jan 2018)
R
23
star
28

yule-rstudio

โ›„๏ธ๐ŸŽ„๐Ÿ–ฅ A Holiday Theme for RStudio
22
star
29

snippets

My snippets for RStudio (or elsewhere)
Vim Snippet
21
star
30

slides

HTML
20
star
31

tiktokrmd

Embed TikTok Videos in R Markdown
R
18
star
32

xaringan-logo

xaringan template with logo on all slides
HTML
17
star
33

tweets-of-the-year

R
16
star
34

xaringan2powerpoint

a snarky powerpoint from xaringan demo
HTML
16
star
35

drake-intro

Reproducible Data Workflows with Drake
R
14
star
36

getcitations

R script to extract pandoc citations from markdown text and create local .bib file from a master BibTeX library.
R
14
star
37

applause

๐Ÿ‘ Zero-Configuration Applause/Claps/Kudos Button for R Markdown and Shiny apps
R
14
star
38

tidyjs-r

Tidy Data with JavaScript and tidy.js
R
14
star
39

sprinkles

Utility CSS and JavaScript for R Markdown
JavaScript
14
star
40

rstudio-global-2021-calendar

Build your talk calendar for rstudio::global(2021)
R
13
star
41

garrickadenbuie-com

My personal website
HTML
13
star
42

intro-to-git-for-scientists

Intro to git for scientists and other regular people
TeX
12
star
43

de-iris-my-repos

It's time to move on from iris
R
12
star
44

repromonkey

๐Ÿ’ A Reproducibility Chaos Monkey
R
12
star
45

oceanic-eighties

๐Ÿ‘จโ€๐ŸŽค Oceanic Eighties Theme for RStudio
11
star
46

js4shiny-frappeCharts

Building an HTML Widget, a demonstration
HTML
11
star
47

synamyn

Synonyms! An RStudio addin interface for ropenscilabs/syn
R
10
star
48

gathertweet

Commandline utility for quick {rtweet} tweet gathering
R
9
star
49

r-colors-css

A utility CSS stylesheet with R's color names
HTML
8
star
50

rsprefs

Manage and Sync Your RStudio Preferences
R
8
star
51

js4shiny-drumkit

HTML
8
star
52

branchMover

An RStudio Addin to Help Move the Default Branch of Your GitHub Repos
R
8
star
53

rstudio-ide-tips-demo

Companion to rstudio-ide-tips
R
7
star
54

gadenbuie

7
star
55

mctestanalysis

๐Ÿ“š Apps and reports for multiple-choice test analysis in R with Shiny
R
6
star
56

rstudio-ide-tips

Slides for RStudio IDE Tips
JavaScript
6
star
57

rstudioAddinFriend

RStudio addin to help you build RStudio addins
R
5
star
58

drake-rstudio-jobs-example

R
5
star
59

extra-awesome-xaringan

R
4
star
60

pagedown-cheatsheet

JavaScript
4
star
61

docker-rstudio-keras

๐Ÿณ RStudio + tidyverse + keras (cpu)
Dockerfile
4
star
62

positron-plus-1-e

A Positron extension pack for dev and data science.
4
star
63

rstatsnyc-2018-tweets

Tweets from #rstatsnyc -- remix of rsconf tweet shiny app
R
3
star
64

ten-thousand-functions

Ten Thousand Reasons to Love Functions
CSS
3
star
65

msglooker

A Shiny App to View And Export Outlook Messages
R
3
star
66

crantrack

Hourly snapshots of CRAN's incoming packages folder
R
3
star
67

fwiffer

๐Ÿ“โœจ Fixed width file definitions made easy
R
3
star
68

xaringan-club

A place to talk about xaringan
HTML
3
star
69

js4shiny-workshop-webpage

HTML
3
star
70

rstudioconf-notes

HTML
2
star
71

rocker-verse-metaflow

rocker/verse + {metaflow}
Dockerfile
2
star
72

nonlinear-opt-notes

Class notes for Nonlinear Optimization and Game Theory at USF, Spring 2016
2
star
73

rstats-tweets

R
2
star
74

alix

Warn About Accessibility Issues in HTML Documents and Apps
R
2
star
75

quarto-partials

Partial content templates for Quarto
Lua
1
star
76

resume

HTML
1
star
77

podcasts

R-based podcast catcher
R
1
star
78

ms-render-ui-delay

R
1
star
79

aws-p2-setup

My AWS EC2 p2 instance setup with nvidia-docker
Shell
1
star
80

usf-boot-camp-R

Slides and materials for R sessions at USF Code & Data Boot Camp 2014
R
1
star
81

xaringan-line-focus

HTML
1
star
82

rmedicine-2024-bslib

Next Generation Shiny Apps with bslib
R
1
star
83

revealjs-text-resizer

Resize text on quarto slides
HTML
1
star
84

quarto-reprex-listing-chomp

EJS
1
star
85

docker-shinycannon

Dockerfile
1
star
86

speedDate

Quick Date Format Strings for strftime
R
1
star
87

quarto-tachyons

Tachyons Utility CSS for Quarto
CSS
1
star