Skip to content

Commit

Permalink
Update 08_Intro_plot_assembly.md
Browse files Browse the repository at this point in the history
Added  figures to lesson 8
  • Loading branch information
cxli233 authored Jul 9, 2023
1 parent b2e8b88 commit 0c4e75f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Quick_data_vis/Lessons/08_Intro_plot_assembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ A2
A3
```

![A1](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_A1.png)

![A2](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_A2.png)

![A3](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_A3.png)

### The design of the composite
To create a composite, we use the `wrap_plots()` function from `patchwork`.
The name is somewhat self-explanatory as for wrapping plots into a larger one.
Expand Down Expand Up @@ -195,6 +201,9 @@ wrap_plots(A1, A2, A3,
ggsave("../Results/08_A_1.png", height = 6, width = 6)
```

![A_1](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_A_1.png)

The way `wrap_plots()` matches sub-panel names to parts A, B, and C is by the order.
In this case, the first sub-panel name (A1) provided is part A, and so on.

Expand All @@ -214,6 +223,9 @@ wrap_plots(A1, A2, A3,
ggsave("../Results/08_A_2.png", height = 6, width = 6)
```

![A_2](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_A_2.png)

For example, vector `c(0.3, 1)` passed on to the `widths` option specifies that the 1st column should be 0.3 of the width of the 2nd column.
Notice we only 2 rows and columns, so the heights and widths vectors each have 2 numbers.
However, if the dimension of the design is different, the heights & widths vectors must have matching dimension too.
Expand All @@ -239,6 +251,9 @@ Panel_A <- wrap_plots(A1 +
Panel_A
ggsave("../Results/08_A.png", height = 6, width = 6)
```

![A](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_A.png)

Now we have panel A!

## Hierarchical assembly
Expand All @@ -252,6 +267,10 @@ Panel_B
Panel_C
```

![B](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_B.png)

![C](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_C.png)

Let's say we want panel A and panel B to be in the left column, panel C alone take up the entire right column, what should the design argument be?
```{r}
c("AC
Expand All @@ -275,6 +294,9 @@ Again, we can control that by calling `widths = ` and `heights = ` within `wrap_
ggsave("../Results/08_assembled.png", height = 7, width = 8)
```

![assembled](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_assembled.png)

Now we are really close.
Notice that only panel A is labeled?
We want panel B to be labeled with a "B" and panel C to be labeled with a "C".
Expand All @@ -294,6 +316,9 @@ We just need to append `+ labs(tag = "B")` and `+ labs(tag = "C")` to the respec
ggsave("../Results/08_assembled_label.png", height = 7, width = 8)
```

![assembled_labeled](https://github.com/cxli233/Online_R_learning/blob/master/Quick_data_vis/Results/08_assembled_label.png)

Done!
Great, we have a publication ready figure!

Expand Down

0 comments on commit 0c4e75f

Please sign in to comment.