-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetting-started.qmd
84 lines (64 loc) · 1.87 KB
/
getting-started.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
title: "Getting started"
execute:
message: false
warning: false
---
This quick start guide is largely inspired from the excellent [workshop by Danielle Navarro](https://art-from-code.netlify.app/).
```{r}
library(tidyverse)
# let's remove any labels and scales
theme_set(theme_void() + theme(legend.position = "none"))
```
<details><summary>(Optional) recording the making of the plot</summary>
```{r}
#| eval: false
library(camcorder) # optional! For getting the gif at the end.
gg_record(
dir = file.path(tempdir(), "recording"), # where to save the recording
device = "jpeg", # device to use to save images
width = 4, # width of saved image
height = 4, # height of saved image
units = "in", # units for width and height
dpi = 300 # dpi to use when saving image
)
```
</details>
Start with any data you like, but we are going to plot the data in the `mtcars` dataset. We can start with some simple scatter plot.
```{r}
ggplot(mtcars, aes(wt, disp, color = factor(am))) +
geom_point(size = 5) +
scale_color_manual(values = c("skyblue", "orange"))
```
Now let's have some fun!
```{r}
g1 <- ggplot(mtcars, aes(wt, disp)) +
geom_segment(aes(xend = 0, yend = 0, linewidth = hp)) +
geom_point(size = 5, color = "black", aes(wt - 0.02, disp - 1)) +
geom_point(aes(color = factor(am)), size = 5) +
scale_color_manual(values = c("skyblue", "orange")) +
scale_linewidth_continuous(range = c(0.05, 1))
g1
```
```{r}
g1 + coord_polar()
```
```{r}
g1 +
coord_polar("y") +
annotate("point", size = 20, x = 0, y = 0) +
annotate("point", size = 3, x = 0.5, y = 1, color = "white")
```
```{r}
#| code-fold: true
#| code-summary: "Code to create gif"
#| eval: false
gg_playback(
name = "getting-started.gif",
first_image_duration = 5,
last_image_duration = 15,
frame_duration = .7,
image_resize = 600
)
```
