Fix figure manipulation

This commit is contained in:
Hadley Wickham
2022-11-18 10:42:43 -06:00
parent 78a1c12fe7
commit 89a854b7d0
15 changed files with 114 additions and 115 deletions

View File

@@ -116,8 +116,8 @@ Primary and foreign keys</h2>
<div class="cell">
<div class="cell-output-display">
<figure id="fig-join-closest"><p><img src="diagrams/relational.png" alt="The relationships between airports, planes, flights, weather, and airlines datasets from the nycflights13 package. airports$faa connected to the flights$origin and flights$dest. planes$tailnum is connected to the flights$tailnum. weather$time_hour and weather$origin are jointly connected to flights$time_hour and flights$origin. airlines$carrier is connected to flights$carrier. There are no direct connections between airports, planes, airlines, and weather data frames." width="502"/></p>
<figcaption>Figure 19.1: Connections between all five data frames in the nycflights13 package. Variables making up a primary key are coloured grey, and are connected to their corresponding foreign keys with arrows.</figcaption>
<figure id="fig-flights-relationships"><p><img src="diagrams/relational.png" alt="The relationships between airports, planes, flights, weather, and airlines datasets from the nycflights13 package. airports$faa connected to the flights$origin and flights$dest. planes$tailnum is connected to the flights$tailnum. weather$time_hour and weather$origin are jointly connected to flights$time_hour and flights$origin. airlines$carrier is connected to flights$carrier. There are no direct connections between airports, planes, airlines, and weather data frames." width="502"/></p>
<figcaption>Connections between all five data frames in the nycflights13 package. Variables making up a primary key are coloured grey, and are connected to their corresponding foreign keys with arrows.</figcaption>
</figure>
</div>
</div>
@@ -500,8 +500,8 @@ y &lt;- tribble(
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/setup.png" alt="x and y are two data frames with 2 columns and 3 rows, with contents as described in the text. The values of the keys are coloured: 1 is green, 2 is purple, 3 is orange, and 4 is yellow." width="160"/></p>
<figcaption class="figure-caption">Figure 19.2: Graphical representation of two simple tables. The coloured <code>key</code> columns map background colour to key value. The grey columns represent the “value” columns that are carried along for the ride.</figcaption>
<figure id="fig-join-setup"><p><img src="diagrams/join/setup.png" alt="x and y are two data frames with 2 columns and 3 rows, with contents as described in the text. The values of the keys are coloured: 1 is green, 2 is purple, 3 is orange, and 4 is yellow." width="160"/></p>
<figcaption>Graphical representation of two simple tables. The coloured key columns map background colour to key value. The grey columns represent the “value” columns that are carried along for the ride.<code>key</code> columns map background colour to key value. The grey columns represent the “value” columns that are carried along for the ride.</figcaption>
</figure>
</div>
</div>
@@ -509,8 +509,8 @@ y &lt;- tribble(
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/setup2.png" alt="x and y are placed at right-angles, with horizonal lines extending from x and vertical lines extending from y. There are 3 rows in x and 3 rows in y, which leads to nine intersections representing nine potential matches." width="170"/></p>
<figcaption class="figure-caption">Figure 19.3: To understand how joins work, its useful to think of every possible match. Here we show that with a grid of connecting lines.</figcaption>
<figure id="fig-join-setup2"><p><img src="diagrams/join/setup2.png" alt="x and y are placed at right-angles, with horizonal lines extending from x and vertical lines extending from y. There are 3 rows in x and 3 rows in y, which leads to nine intersections representing nine potential matches." width="170"/></p>
<figcaption>To understand how joins work, its useful to think of every possible match. Here we show that with a grid of connecting lines.</figcaption>
</figure>
</div>
</div>
@@ -518,8 +518,8 @@ y &lt;- tribble(
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/inner.png" alt="x and y are placed at right-angles with lines forming a grid of potential matches. Keys 1 and 2 appear in both x and y, so we get a match, indicated by a dot. Each dot corresponds to a row in the output, so the resulting joined data frame has two rows." width="363"/></p>
<figcaption class="figure-caption">Figure 19.4: An inner join matches each row in <code>x</code> to the row in <code>y</code> that has the same value of <code>key</code>. Each match becomes a row in the output.</figcaption>
<figure id="fig-join-inner"><p><img src="diagrams/join/inner.png" alt="x and y are placed at right-angles with lines forming a grid of potential matches. Keys 1 and 2 appear in both x and y, so we get a match, indicated by a dot. Each dot corresponds to a row in the output, so the resulting joined data frame has two rows." width="363"/></p>
<figcaption>An inner join matches each row in x to the row in y that has the same value of key. Each match becomes a row in the output.<code>x</code> to the row in <code>y</code> that has the same value of <code>key</code>. Each match becomes a row in the output.</figcaption>
</figure>
</div>
</div>
@@ -529,8 +529,8 @@ y &lt;- tribble(
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/left.png" alt="Compared to the previous diagram showing an inner join, the y table gets a new virtual row containin NA that will match any row in x that didn't otherwise match. This means that the output now has three rows. For key = 3, which matches this virtual row, val_y takes value NA." width="385"/></p>
<figcaption class="figure-caption">Figure 19.5: A visual representation of the left join where every row in <code>x</code> appears in the output.</figcaption>
<figure id="fig-join-left"><p><img src="diagrams/join/left.png" alt="Compared to the previous diagram showing an inner join, the y table gets a new virtual row containin NA that will match any row in x that didn't otherwise match. This means that the output now has three rows. For key = 3, which matches this virtual row, val_y takes value NA." width="385"/></p>
<figcaption>A visual representation of the left join where every row in x appears in the output.<code>x</code> appears in the output.</figcaption>
</figure>
</div>
</div>
@@ -540,8 +540,8 @@ y &lt;- tribble(
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/right.png" alt="Compared to the previous diagram showing an left join, the x table now gains a virtual row so that every row in y gets a match in x. val_x contains NA for the row in y that didn't match x." width="380"/></p>
<figcaption class="figure-caption">Figure 19.6: A visual representation of the right join where every row of <code>y</code> appears in the output.</figcaption>
<figure id="fig-join-right"><p><img src="diagrams/join/right.png" alt="Compared to the previous diagram showing an left join, the x table now gains a virtual row so that every row in y gets a match in x. val_x contains NA for the row in y that didn't match x." width="380"/></p>
<figcaption>A visual representation of the right join where every row of y appears in the output.<code>y</code> appears in the output.</figcaption>
</figure>
</div>
</div>
@@ -551,8 +551,8 @@ y &lt;- tribble(
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/full.png" alt="Now both x and y have a virtual row that always matches. The result has 4 rows: keys 1, 2, 3, and 4 with all values from val_x and val_y, however key 2, val_y and key 4, val_x are NAs since those keys don't have a match in the other data frames." width="388"/></p>
<figcaption class="figure-caption">Figure 19.7: A visual representation of the full join where every row in <code>x</code> and <code>y</code> appears in the output.</figcaption>
<figure id="fig-join-full"><p><img src="diagrams/join/full.png" alt="Now both x and y have a virtual row that always matches. The result has 4 rows: keys 1, 2, 3, and 4 with all values from val_x and val_y, however key 2, val_y and key 4, val_x are NAs since those keys don't have a match in the other data frames." width="388"/></p>
<figcaption>A visual representation of the full join where every row in x and y appears in the output.<code>x</code> and <code>y</code> appears in the output.</figcaption>
</figure>
</div>
</div>
@@ -561,8 +561,8 @@ y &lt;- tribble(
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/venn.png" alt="Venn diagrams for inner, full, left, and right joins. Each join represented with two intersecting circles representing data frames x and y, with x on the right and y on the left. Shading indicates the result of the join." width="385"/></p>
<figcaption class="figure-caption">Figure 19.8: Venn diagrams showing the difference between inner, left, right, and full joins.</figcaption>
<figure id="fig-join-venn"><p><img src="diagrams/join/venn.png" alt="Venn diagrams for inner, full, left, and right joins. Each join represented with two intersecting circles representing data frames x and y, with x on the right and y on the left. Shading indicates the result of the join." width="385"/></p>
<figcaption>Venn diagrams showing the difference between inner, left, right, and full joins.</figcaption>
</figure>
</div>
</div>
@@ -574,8 +574,8 @@ Row matching</h2>
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/match-types.png" alt="A join diagram where x has key values 1, 2, and 3, and y has key values 1, 2, 2. The output has three rows because key 1 matches one row, key 2 matches two rows, and key 3 matches zero rows." width="348"/></p>
<figcaption class="figure-caption">Figure 19.9: The three ways a row in <code>x</code> can match. <code>x1</code> matches one row in <code>y</code>, <code>x2</code> matches two rows in <code>y</code>, <code>x3</code> matches zero rows in y. Note that while there are three rows in <code>x</code> and three rows in the output, there isnt a direct correspondence between the rows.</figcaption>
<figure id="fig-join-match-types"><p><img src="diagrams/join/match-types.png" alt="A join diagram where x has key values 1, 2, and 3, and y has key values 1, 2, 2. The output has three rows because key 1 matches one row, key 2 matches two rows, and key 3 matches zero rows." width="348"/></p>
<figcaption>The three ways a row in x can match. x1 matches one row in y, x2 matches two rows in y, x3 matches zero rows in y. Note that while there are three rows in x and three rows in the output, there isnt a direct correspondence between the rows.<code>x</code> can match. <code>x1</code> matches one row in <code>y</code>, <code>x2</code> matches two rows in <code>y</code>, <code>x3</code> matches zero rows in y. Note that while there are three rows in <code>x</code> and three rows in the output, there isnt a direct correspondence between the rows.</figcaption>
</figure>
</div>
</div>
@@ -683,16 +683,16 @@ Filtering joins</h2>
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/semi.png" alt="A join diagram with old friends x and y. In a semi join, only the presence of a match matters so the output contains the same columns as x." width="318"/></p>
<figcaption class="figure-caption">Figure 19.10: In a semi-join it only matters that there is a match; otherwise values in <code>y</code> dont affect the output.</figcaption>
<figure id="fig-join-semi"><p><img src="diagrams/join/semi.png" alt="A join diagram with old friends x and y. In a semi join, only the presence of a match matters so the output contains the same columns as x." width="318"/></p>
<figcaption>In a semi-join it only matters that there is a match; otherwise values in y dont affect the output.<code>y</code> dont affect the output.</figcaption>
</figure>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/anti.png" alt="An anti-join is the inverse of a semi-join so matches are drawn with red lines indicating that they will be dropped from the output." width="317"/></p>
<figcaption class="figure-caption">Figure 19.11: An anti-join is the inverse of a semi-join, dropping rows from <code>x</code> that have a match in <code>y</code>.</figcaption>
<figure id="fig-join-anti"><p><img src="diagrams/join/anti.png" alt="An anti-join is the inverse of a semi-join so matches are drawn with red lines indicating that they will be dropped from the output." width="317"/></p>
<figcaption>An anti-join is the inverse of a semi-join, dropping rows from x that have a match in y.<code>x</code> that have a match in <code>y</code>.</figcaption>
</figure>
</div>
</div>
@@ -716,8 +716,8 @@ Non-equi joins</h1>
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/inner-both.png" alt="A join diagram showing an inner join betwen x and y. The result now includes four columns: key.x, val_x, key.y, and val_y. The values of key.x and key.y are identical, which is why we usually only show one. " width="415"/></p>
<figcaption class="figure-caption">Figure 19.12: An left join showing both <code>x</code> and <code>y</code> keys in the output.</figcaption>
<figure id="fig-inner-both"><p><img src="diagrams/join/inner-both.png" alt="A join diagram showing an inner join betwen x and y. The result now includes four columns: key.x, val_x, key.y, and val_y. The values of key.x and key.y are identical, which is why we usually only show one. " width="415"/></p>
<figcaption>An left join showing both x and y keys in the output.<code>x</code> and <code>y</code> keys in the output.</figcaption>
</figure>
</div>
</div>
@@ -725,8 +725,8 @@ Non-equi joins</h1>
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/gte.png" alt="A join diagram illustrating join_by(key &gt;= key). The first row of x matches one row of y and the second and thirds rows each match two rows. This means the output has five rows containing each of the following (key.x, key.y) pairs: (1, 1), (2, 1), (2, 2), (3, 1), (3, 2)." width="385"/></p>
<figcaption class="figure-caption">Figure 19.13: A non-equi join where the <code>x</code> key must greater than or equal to than the <code>y</code> key. Many rows generate multiple matches.</figcaption>
<figure id="fig-join-gte"><p><img src="diagrams/join/gte.png" alt="A join diagram illustrating join_by(key &gt;= key). The first row of x matches one row of y and the second and thirds rows each match two rows. This means the output has five rows containing each of the following (key.x, key.y) pairs: (1, 1), (2, 1), (2, 2), (3, 1), (3, 2)." width="385"/></p>
<figcaption>A non-equi join where the x key must greater than or equal to than the y key. Many rows generate multiple matches.<code>x</code> key must greater than or equal to than the <code>y</code> key. Many rows generate multiple matches.</figcaption>
</figure>
</div>
</div>
@@ -748,8 +748,8 @@ Cross joins</h2>
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/cross.png" alt="A join diagram showing a dot for every combination of x and y." width="155"/></p>
<figcaption class="figure-caption">Figure 19.14: A cross join matches each row in <code>x</code> with every row in <code>y</code>.</figcaption>
<figure id="fig-join-cross"><p><img src="diagrams/join/cross.png" alt="A join diagram showing a dot for every combination of x and y." width="155"/></p>
<figcaption>A cross join matches each row in x with every row in y.<code>x</code> with every row in <code>y</code>.</figcaption>
</figure>
</div>
</div>
@@ -777,8 +777,8 @@ Inequality joins</h2>
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/lt.png" width="185"/></p>
<figcaption class="figure-caption">Figure 19.15: An inequality join where <code>x</code> is joined to <code>y</code> on rows where the key of <code>x</code> is less than the key of <code>y</code>. This makes a triangular shape in the top-left corner.</figcaption>
<figure id="fig-join-lt"><p><img src="diagrams/join/lt.png" width="185"/></p>
<figcaption>An inequality join where x is joined to y on rows where the key of x is less than the key of y. This makes a triangular shape in the top-left corner.<code>x</code> is joined to <code>y</code> on rows where the key of <code>x</code> is less than the key of <code>y</code>. This makes a triangular shape in the top-left corner.</figcaption>
</figure>
</div>
</div>
@@ -807,8 +807,8 @@ Rolling joins</h2>
<div class="cell">
<div class="cell-output-display">
<figure class="figure"><p><img src="diagrams/join/closest.png" alt="A rolling join is a subset of an inequality join so some matches are grayed out indicating that they're not used because they're not the &quot;closest&quot;." width="262"/></p>
<figcaption class="figure-caption">Figure 19.16: A following join is similar to a greater-than-or-equal inequality join but only matches the first value.</figcaption>
<figure id="fig-join-closest"><p><img src="diagrams/join/closest.png" alt="A rolling join is a subset of an inequality join so some matches are grayed out indicating that they're not used because they're not the &quot;closest&quot;." width="262"/></p>
<figcaption>A following join is similar to a greater-than-or-equal inequality join but only matches the first value.</figcaption>
</figure>
</div>
</div>