-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
132 lines (95 loc) · 4.56 KB
/
README.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
output: github_document
---
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
![Commits](https://img.shields.io/github/last-commit/Flowminder/FlowmindeR)
<!-- badges: end -->
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
dpi = 450
)
library(FlowmindeR)
```
# Overview
`FlowmindeR` is a package used for helping produce consistent graphical outputs for Flowminder work in line with branding guidance. It provides sets of themes and helper functions in three categories:
- **Plots**: A ggplot style for producing Flowminder graphics for producing graphs in `ggplot`
- **Documents**: Templates to produce PDF and HTML documents through R Markdown
- **Maps**: Convenient links to use Flowminder themed from Mapbox
## Installation
`FlowmindeR` is not on CRAN, so you will have to install it directly from Github using `remotes`. If you do not have the `remotes` package installed, you will have to run the first line in the code below as well.
```{r, eval = F}
# install.packages('remotes')
remotes::install_github('Flowminder/FlowmindeR')
```
### Plotting
The package helps set a default theme for ggplot graphics. This is set globally for all your analysis through the `set_fm_style()` function, which has no arguments and used to set the default ggplot themes. This sets text size, font and colour, axis lines, axis text and many other standard chart components into the Flowminder style.
Example of how it is used in a standard workflow:
```{r, fig.width = 6, fig.height=3}
library(ggplot2)
library(gapminder) # Used as example data
library(tidyverse)
# Set the defaults
set_fm_style()
gapminder_2007 <-
gapminder %>%
filter(year == 2007)
ggplot(gapminder_2007, aes(x = lifeExp, y = gdpPercap, colour = continent)) +
geom_point() +
labs(x= "Life Expectancy",
colour = "Continent",
y = "GDP per Capita\n($/person)",
title = "GDP vs Life Expectancy")
```
The function is pretty basic and does not change or adapt based on the type of chart you are making, so in some cases you will need to make additional `theme` arguments in your ggplot chain if you want to make any additions or changes to the style, for example to add or remove gridlines etc. Detailed examples on how to use the functions included within the `FlowmindeR` package to produce graphics are included in the [full vignettes](articles/graphics.html), as well as a more general reference manual for working with `ggplot2`.
### R Markdown Templates
R Markdown provides a tool which enables you to combine code and written text, much like Jupyter notebooks. However, the power of R Markdown is that it offers much greater flexibility in how the outputted document can be formatted. As such, it is possible to produce fully branded and functioning PDFs and HTML reports directly from your analysis.
```{r rmarkdown, echo = F, fig.cap= "R Markdown output formats"}
knitr::include_graphics("https://flowminder.github.io/FlowmindeR/rmarkdownFormats.png")
```
The package contains two functions which can be used: `fm_pdf` and `fm_html`, which can be used in the `output` within the document's YAML settings:
```{yaml}
---
title: "My document"
output: FlowmindeR::fm_pdf: default
---
```
For more information, see the [vignette explaining R Markdown](articles/rmarkdown.html)
### Basemaps
The app offers convenient functions to access custom Mapbox basemaps for plots through the `fm_mapbox_styles` function. Note, you will have to register with MapBox to get an access key for this functionality to work. For details, refer to the [vignette explaining maps](articles/maps.html)
```{r, include = F}
library(ceramic)
library(tmap)
basemap1 <-
cc_location(loc = cbind(-1.5, 50.99), buffer = 2e5,
base_url = fm_mapbox_styles("basic"),
max_tiles = 9)
basemap2 <-
cc_location(loc = cbind(-1.5, 50.99), buffer = 2e5,
base_url = fm_mapbox_styles("no borders"),
max_tiles = 9)
basemap3 <-
cc_location(loc = cbind(-1.5, 50.99), buffer = 2e5,
base_url = fm_mapbox_styles("no names"),
max_tiles = 9)
```
```{r fig.width=9, fig.height=3, echo=F}
map1 <-
tm_shape(basemap1) +
tm_rgb() +
tm_layout(frame = FALSE)
map2 <-
tm_shape(basemap2) +
tm_rgb() +
tm_layout(frame = FALSE)
map3 <-
tm_shape(basemap3) +
tm_rgb() +
tm_layout(frame = FALSE)
tmap_arrange(map1, map2, map3)
```