-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathREADME.Rmd
executable file
·175 lines (130 loc) · 5.15 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
output: github_document
---
customLayout
========================================================
<!-- 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-"
)
```
[![GitHub stars](https://img.shields.io/github/stars/zzawadz/customLayout.svg?style=social&label=Stars)](https://github.com/zzawadz/customLayout/stargazers)
[![GitHub watchers](https://img.shields.io/github/watchers/zzawadz/customLayout.svg?style=social&label=Watch)](https://github.com/zzawadz/customLayout)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/customLayout)](https://cran.r-project.org/package=customLayout)
[![Downloads](https://cranlogs.r-pkg.org/badges/customLayout)](https://CRAN.R-project.org/package=customLayout)
[![](https://cranlogs.r-pkg.org/badges/grand-total/customLayout)](https://CRAN.R-project.org/package=customLayout)
[![Travis-CI Build Status](https://travis-ci.org/zzawadz/customLayout.svg?branch=master)](https://travis-ci.org/zzawadz/customLayout)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/zzawadz/customLayout?branch=master&svg=true)](https://ci.appveyor.com/project/zzawadz/customLayout)
[![Coverage Status](https://img.shields.io/codecov/c/github/zzawadz/customLayout/master.svg)](https://codecov.io/github/zzawadz/customLayout?branch=master)
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
`customLayout` is a simple extension of the basic `layout` function from `R` but it works not only with `base` and `grid` graphics systems, but also with PowerPoint slides using `officer` package.
## Instalation:
`customLayout` is available on CRAN:
```{r, eval=FALSE}
install.packages("customLayout")
```
The development version can be installed from GitHub using `devtools`:
```{r, eval=FALSE}
library(devtools)
install_github("zzawadz/customLayout")
```
## Basic functionality:
You can create layouts in the using the same syntax as in the base `layout` function:
```{r base, message = FALSE, results = 'hide', fig.width = 4, fig.height = 2, fig.keep = 'all', fig.pos = 'H'}
library(customLayout)
lay <- lay_new(
matrix(1:4, nc = 2),
widths = c(3, 2),
heights = c(2, 1))
lay_show(lay)
lay2 <- lay_new(
matrix(1:4, nc = 2),
widths = c(3, 5),
heights = c(2, 4))
lay_show(lay2)
```
But the main strength of this package is in combining created layouts with specific ratio:
```{r combine, message = FALSE, results = 'hide', fig.width = 4, fig.height = 2, tidy = FALSE}
# lay will be 3 times wider that lay2
# all ascects in lay and lay2 will be preserved
cl = lay_bind_col(lay, lay2, widths = c(3, 1))
lay_show(cl)
```
You can create even more complicated layouts:
```{r complicated, message = FALSE, results = 'hide', fig.width = 4, fig.height = 2}
lay3 <- lay_new(matrix(1:2))
lay4 <- lay_bind_row(cl, lay3, heights = c(5, 2))
lay_show(lay4)
lay5 <- lay_bind_col(lay4, lay3, widths = c(5, 2))
lay_show(lay5)
```
## Split layout
You can create very complicated layouts by splitting one field:
```{r split, message = FALSE, results = 'hide', fig.width = 4, fig.height = 2, tidy = FALSE, fig.keep='all'}
library(customLayout)
lay <- lay_new(
matrix(1:4, nc = 2),
widths = c(3, 2),
heights = c(2, 1))
lay_show(lay)
lay2 <- lay_new(
matrix(1:4, nc = 2),
widths = c(3, 5),
heights = c(2, 4))
lay_show(lay2)
# Split field 4 from lay into lay2:
slay <- lay_split_field(lay, lay2, field = 4)
lay_show(slay)
```
## Example session:
### Base graphics
```{r example,message = FALSE, results = 'hide', fig.width = 10, fig.height = 6}
library(customLayout)
par(mar = c(3, 2, 2, 1))
lay <- lay_new(
matrix(1:4, nc = 2),
widths = c(3, 2),
heights = c(2, 1))
lay2 <- lay_new(matrix(1:3))
cl <- lay_bind_col(lay, lay2, widths = c(3, 1))
lay_set(cl) # initialize drawing area
set.seed(123)
plot(1:100 + rnorm(100))
plot(rnorm(100), type = "l")
hist(rnorm(500))
acf(rnorm(100))
pie(c(3, 4, 6), col = 2:4)
pie(c(3, 2, 7), col = 2:4 + 3)
pie(c(5, 4, 2), col = 2:4 + 6)
```
## Grid graphics (ggplot2 and friends)
```{r examplegrid,message = FALSE, fig.width = 10, fig.height = 6}
library(customLayout)
library(ggplot2)
library(gridExtra)
lay <- lay_new(
matrix(1:2, ncol = 1))
lay2 <- lay_new(matrix(1:3))
cl <- lay_bind_col(lay, lay2, widths = c(3, 1))
library(ggplot2)
cuts <- sort(unique(diamonds[["cut"]]),
decreasing = TRUE)
make_cut_plot <- function(cut) {
dd <- diamonds[diamonds[["cut"]] == cut, ]
pl <- ggplot(dd) +
geom_point(aes(carat, price)) +
facet_wrap("cut")
pl
}
plots <- lapply(cuts, make_cut_plot)
lay_grid(plots, cl)
```
## PowerPoint support
Layouts created using `customLayout` package can be used to arrange elements on the PowerPoint slide. For the detailed description please refer to [the vignette](https://www.customlayout.zstat.pl/articles/layouts-for-officer-power-point-document.html):
```{r, eval=FALSE}
vignette("layouts-for-officer-power-point-document", package = "customLayout")
```
![](man/figures/officer-text.png)<!-- -->