-
Notifications
You must be signed in to change notification settings - Fork 0
/
scales_microflip.Rmd
95 lines (70 loc) · 2.13 KB
/
scales_microflip.Rmd
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
84
85
86
87
88
89
90
91
92
93
94
---
title: "Customizing Plot Scales"
subtitle: "Customizing Your Scales in ggplot2"
author:
- "Peter Higgins"
date: '`r Sys.Date()`'
output:
xaringan::moon_reader:
lib_dir: libs
css: xaringan-themer.css
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
ratio: 16:9
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.width = 6, message = FALSE, warning = FALSE, comment = "", cache = FALSE, fig.retina = 3)
library(flipbookr)
library(xaringan)
library(xaringanthemer)
library(tidyverse)
library(medicaldata)
library(janitor)
prostate <- medicaldata::blood_storage %>% clean_names() %>% as_tibble()
```
```{r xaringan-themer, include=FALSE, warning=FALSE}
library(xaringanthemer)
xaringanthemer::style_duo_accent(
primary_color = "#00274C",
secondary_color = "#FFCB05",
header_font_google = google_font("Lato"),
code_font_google = google_font("Roboto Mono"),
base_font_size = "20px",
code_font_size = "0.8rem",
)
```
```{r xaringanExtra-share-again, echo=FALSE}
xaringanExtra::use_share_again()
# adds share bar to flipbooks
```
### Customizing Plot Scales
#### There are Multiple Functions to Customize the Default Scales of Your ggplot2 plot.
- The {ggplot2} package supplies default scales and labels for your plots so that you can get a reasonable result quickly.
- However, you can customize these scales by adding (+) lines to your plot code that have the format of scales_(x|y|color|shape)_description().
- Let's see an example
---
```{r scales1, include = FALSE, eval = FALSE}
prostate %>%
# slow plot
ggplot() +
aes(x = factor(recurrence)) +
aes(y = p_vol) +
geom_jitter() +
aes(color = factor(recurrence)) +
# expand x margins
scale_x_discrete(expand = expansion(mult=1.2)) +
# set y limits
scale_y_continuous(limits= c(0,90)) +
# format color legend
scale_color_discrete(name = "Recurrence",
labels = c("No Recurrence", "Recurrence"))
```
`r chunk_reveal("scales1",
break_type = "auto",
title = "Scales 1: x,y, and color")`
---
class: inverse, center
# End of This Flipbook
## Let's Learn How to Do This!