You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/create_custom_layout.Rmd
+17-14Lines changed: 17 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,9 @@ vignette: >
8
8
%\VignetteIndexEntry{Create Custom Layout}
9
9
%\VignetteEngine{knitr::rmarkdown}
10
10
%\VignetteEncoding{UTF-8}
11
+
editor_options:
12
+
markdown:
13
+
wrap: 72
11
14
---
12
15
13
16
```{r, include = FALSE}
@@ -29,7 +32,7 @@ Please note that creating a custom layout may not be required. It is intended fo
29
32
30
33
A layout is a grid structure defined by the number of rows and columns which creates spaces or cells where text elements can then be added. Each cell is then defined by the rows and columns it spans.
31
34
32
-
```{r}
35
+
```{r layout-basics}
33
36
library(gridify)
34
37
# (to use |> version 4.1.0 of R is required, for lower versions we recommend %>% from magrittr)
35
38
library(magrittr)
@@ -43,7 +46,7 @@ show_layout(simple_layout())
43
46
44
47
Here is an example layout. All arguments will be explained below.
45
48
46
-
```{r}
49
+
```{r example-layout}
47
50
#| results: hide
48
51
49
52
new_layout <- gridifyLayout(
@@ -103,7 +106,7 @@ The layout needs to have a margin defined to determine how much space there shou
103
106
104
107
The margin must be a call to `grid::unit(...)` where a vector with arguments `t`, `r`, `b` and `l` are given values, this is for the top, right, bottom and left margins respectively e.g.
105
108
106
-
```{r}
109
+
```{r margin-argument}
107
110
#| eval: false
108
111
109
112
# a 10% margin on all sides
@@ -116,7 +119,7 @@ The object's location is defined in the `object` argument of `gridifyLayout()`.
116
119
117
120
The arguments `height` and `width` of `gridifyObject()` determine how much of the space the object should take up within the cell(s) location. The default values are `1`, which is the equivalent of 100% of the width/height of the area.
118
121
119
-
```{r}
122
+
```{r adding-object-argument}
120
123
#| eval: false
121
124
122
125
# an object that spans only row 3 but both columns 1 and 2
@@ -132,26 +135,26 @@ For transparency, this section will explain how the `scales` argument works, and
132
135
133
136
In the predefined simple and complex layouts, you can choose between `"free"` and `"fixed"` scales. When using `"free"` scales, row heights are proportionally 15%, 70% and 15% of the total area. Conversely, with `"fixed"` scales, row heights are determined by the number of lines required for each text element, with any remaining space allocated to the object.
134
137
135
-
```{r}
138
+
```{r scales-argument-free}
136
139
simple_layout(scales = "free")
137
140
```
138
141
139
-
```{r}
142
+
```{r show-scales-argument-free}
140
143
show_layout(simple_layout(scales = "free"))
141
144
```
142
145
143
-
```{r}
146
+
```{r scales-argument-fixed}
144
147
simple_layout(scales = "fixed")
145
148
```
146
149
147
-
```{r}
150
+
```{r show-scales-argument-fixed}
148
151
# As no lines were defined, the object takes up the whole space below
149
152
show_layout(simple_layout(scales = "fixed"))
150
153
```
151
154
152
155
Below is an example of how to add scales to a custom layout with options being `npc` or `lines`.
153
156
154
-
```{r}
157
+
```{r how-add-scales-custom-layout}
155
158
scales_example_layout <- function(
156
159
margin = grid::unit(c(t = 0.1, r = 0.1, b = 0.1, l = 0.1), units = "npc"),
157
160
global_gpar = grid::gpar(),
@@ -197,7 +200,7 @@ The cells are the places a user can add their text elements to the output. If a
197
200
198
201
The cells are created by making a call to `gridifyCells()` which requires named arguments returning calls to `gridifyCell()`. The names of these arguments are the names the user will be referencing when adding text elements to the output so make sure they are named appropriately.
199
202
200
-
```{r}
203
+
```{r adding-cells}
201
204
#| eval: false
202
205
gridifyCells(
203
206
company = gridifyCell(row = 1, col = 2, x = 1, hjust = 1, y = 1, vjust = 1),
@@ -248,7 +251,7 @@ local \> default \> global
248
251
249
252
Therefore, any graphical parameter can be overwritten by the users in the calls to `set_cell()`.
250
253
251
-
```{r}
254
+
```{r default-graphical-parameters}
252
255
#| results: hide
253
256
254
257
new_layout <- gridifyLayout(
@@ -280,7 +283,7 @@ gridify(
280
283
281
284
The text element fonts can also be customized easily as per the user requirements.
282
285
283
-
```{r}
286
+
```{r default-graphical-parameters-text}
284
287
#| results: hide
285
288
286
289
new_layout <- gridifyLayout(
@@ -317,7 +320,7 @@ gridify(
317
320
318
321
The `text` argument of `gridifyCell()` can be used to set the default text for a cell. Please note, the text provided by the end user with `set_cell()` will take higher priority and overwrite the default.
319
322
320
-
```{r}
323
+
```{r default-cell-text}
321
324
new_layout <- gridifyLayout(
322
325
nrow = 4L,
323
326
ncol = 2L,
@@ -348,7 +351,7 @@ gridify(
348
351
349
352
To add a watermark to your output, create a cell covering the desired rows and columns and set the transparency of the text, the font size large and the rotation to 45 degrees.
Copy file name to clipboardExpand all lines: vignettes/gridify.Rmd
+8-2Lines changed: 8 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,16 @@
1
1
---
2
2
title: "Get Started with gridify"
3
-
output: rmarkdown::html_vignette
3
+
output:
4
+
rmarkdown::html_vignette:
5
+
toc: true
6
+
toc_depth: 4
4
7
vignette: >
5
8
%\VignetteIndexEntry{Get Started with gridify}
6
9
%\VignetteEngine{knitr::rmarkdown}
7
10
%\VignetteEncoding{UTF-8}
11
+
editor_options:
12
+
markdown:
13
+
wrap: 72
8
14
---
9
15
10
16
```{r, include = FALSE}
@@ -21,7 +27,7 @@ knitr::opts_chunk$set(
21
27
In the pharmaceutical industry, and many other fields that rely heavily on data reporting, there is often a need to create tables and figures with specific text elements — like titles, subtitles, captions, and footnotes — positioned consistently around the output.
22
28
Manually arranging these elements can be time-consuming and prone to inconsistencies across projects.
23
29
24
-
`gridify` addresses this by building on the base R `[grid](https://cran.r-project.org/package=grid)` package, making it easy to add flexible, customizable elements around a plot or table. This ensures a consistent layout for text elements (like headers, footers, etc.) across various output types, such as:
30
+
`gridify` addresses this by building on the base R [grid](https://cran.r-project.org/package=grid) package, making it easy to add flexible, customizable elements around a plot or table. This ensures a consistent layout for text elements (like headers, footers, etc.) across various output types, such as:
0 commit comments