-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-viz.Rmd
114 lines (69 loc) · 2.78 KB
/
04-viz.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# (PART) Visualization {-}
# ggplot2
## Slides {#gg-slides}
Workshop: Introduction to ggplot2
Date: November 2 2017
[Slides](https://slides.robitalec.ca/intro-ggplot.html) and [Resources](https://gitlab.com/robit.a/workshops/-/archive/master/workshops-master.zip?path=intro-ggplot)
```{r, echo = FALSE}
knitr::include_url('https://slides.robitalec.ca/intro-ggplot.html')
```
## Resources {#gg-resources}
* [ggplot2 book](https://ggplot2-book.org/)
* Claus Wilke's course [Data Visualization in R](https://wilkelab.org/SDS375/syllabus.html), book [Fundamentals of Data Visualization](https://clauswilke.com/dataviz/)
* [What makes bad figures bad](https://socviz.co/lookatdata.html#what-makes-bad-figures-bad)
## Facets
```{r, include = FALSE}
library(ggplot2)
data(diamonds)
ggplot(diamonds, aes(depth, price)) +
geom_point()
```
Facet wrap using categorical columns:
```{r}
ggplot(diamonds, aes(depth, price)) +
geom_point() +
facet_wrap(~cut)
```
Facet wrap using automatically binned values:
"What if I look at four separate chunks of the data, with approximately the same number of points"
```{r}
ggplot(diamonds, aes(depth, price)) +
geom_point() +
facet_wrap(~ cut_number(carat, 4))
```
"What if I look at four separate chunks of the data, with the equal ranges in each group?"
```{r}
ggplot(diamonds, aes(depth, price)) +
geom_point() +
facet_wrap(~ cut_interval(carat, 4))
```
"What if I look at four separate chunks of the data, with a specific width of values in each group?"
```{r}
ggplot(diamonds, aes(depth, price)) +
geom_point() +
facet_wrap(~ cut_width(carat, 0.5))
```
## Combining plots
![](https://img.shields.io/badge/-WIP-yellow.svg)
<!-- **TODO: ALR - examples, use ##C layout, & theme** -->
The one and only: [`patchwork`](https://patchwork.data-imaginist.com/).
# Spatial plotting
![](https://img.shields.io/badge/-WIP-yellow.svg)
Lots of examples of spatial plotting of vector data in the [study-area-figure](https://gitlab.com/WEEL_grp/study-area-figures) repository.
Also check out [`tmap`](https://r-tmap.github.io/tmap-book/).
Note: plotting large rasters can be really intensive, so start small or
reduce the resolution. It also might help to write the plot out to a PDF,
instead of trying to view it directly in the RStudio window.
# Cool Packages {#viz-cool}
![](https://img.shields.io/badge/-WIP-yellow.svg)
<!-- **TODO: links, fill, grab from https://ropensci.org/packages/ under vis** -->
## ggplot extensions
* Themes: `ggthemes`
* Annotations: `ggannotate`
* Distribution geometries: `ggdist`
* Labels that repel: `ggrepel`
* Turn ggplots into interactive plots: [`plotly`](https://github.com/plotly/plotly.R#getting-started)
## Spatial plotting
* `mapview`
* `leaflet`
* Coarse scale/simple geometries for plots: `rnaturalearth`