Skip to content

Commit 84231cc

Browse files
committed
addlayer argument should be called add
1 parent c94a60d commit 84231cc

File tree

4 files changed

+15
-36
lines changed

4 files changed

+15
-36
lines changed

R/shape-plot-parts.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ shape.plot.like.ckb <- function(xlims,
291291

292292
#' code for theme
293293
#' @noRd
294-
shape.theme <- function(legend.position, addlayer) {
294+
shape.theme <- function(legend.position, add) {
295295
make_layer(
296296
'# Add theme',
297297
f = "theme",
298298
arg = 'legend.position = {deparse(legend.position)}',
299-
plus = !is.null(addlayer$end)
299+
plus = !is.null(add$end)
300300
)
301301
}
302302

R/shape-plot.R

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,8 @@
4747
#' @param quiet Set to TRUE to not print the plot nor show generated code in the RStudio 'Viewer' pane. (Default: FALSE)
4848
#' @param printplot Print the plot. (Default: !quiet)
4949
#' @param showcode Show the ggplot2 code to generate the plot in RStudio 'Viewer' pane. (Default: !quiet)
50-
#' @param addcode A character vector of code to add to the generated code.
51-
#' The first element should be a regular expression.
52-
#' The remaining elements are added to the generated code just before the first match of a line (trimmed of whitespace) with the regular expression. (Default: NULL)
53-
#' @param addaes Specify additional aesthetics for some ggplot layers.
54-
#' @param addarg Specify additional arguments for some ggplot layers.
55-
#' @param addlayer Adding ggplot layers.
50+
#' @param addaes,addarg,add
51+
#' Methods for customising the plot. See documentation for details.
5652
#' @param envir Environment in which to evaluate the plot code. May be useful when calling this function inside another function.
5753
#'
5854
#' @return A list:
@@ -107,10 +103,9 @@ shape_plot <- function(data,
107103
quiet = FALSE,
108104
printplot = !quiet,
109105
showcode = !quiet,
110-
addcode = NULL,
111106
addaes = NULL,
112107
addarg = NULL,
113-
addlayer = NULL,
108+
add = NULL,
114109
envir = NULL){
115110

116111
# Check arguments ----
@@ -348,10 +343,10 @@ shape_plot <- function(data,
348343

349344
indent(2,
350345

351-
# addlayer$start
352-
if (!is.null(addlayer$start)){
346+
# add$start
347+
if (!is.null(add$start)){
353348
c("# Additional layer",
354-
paste(c(deparse(substitute(addlayer)$start), " +"), collapse = ""),
349+
paste(c(deparse(substitute(add)$start), " +"), collapse = ""),
355350
"")
356351
},
357352

@@ -435,25 +430,18 @@ shape_plot <- function(data,
435430
plotcolour)),
436431

437432
# theme
438-
indent(2, shape.theme(legend.position, addlayer)),
433+
indent(2, shape.theme(legend.position, add)),
439434

440-
# addlayer$end
441-
if (!is.null(addlayer$end)){
435+
# add$end
436+
if (!is.null(add$end)){
442437
c("# Additional layer",
443-
paste(deparse(substitute(addlayer)$end), collapse = ""),
438+
paste(deparse(substitute(add)$end), collapse = ""),
444439
"")
445440
}
446441

447442
)
448443

449444

450-
# add additional code
451-
if (!is.null(addcode)){
452-
plotcode <- append(plotcode,
453-
addcode[2:length(addcode)],
454-
grep(addcode[1], trimws(plotcode))[1]-1)
455-
}
456-
457445

458446
# Show code in RStudio viewer.
459447
if (showcode){ displaycode(plotcode) }

man/shape_plot.Rd

Lines changed: 2 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/customising_plots.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Note that `col.bold`, and `col.diamond` must be column names in the supplied dat
5959

6060

6161
## Adding to the ggplot
62-
In `forest_plot()` you can add additional ggplot objects to the plot with the `add` argument. The argument should be a named list, where the name `start` is an object to be included in the ggplot immediately after `ggplot()` (i.e. before anything else is added to the ggplot) and the name `end` will add to the end.
62+
In `forest_plot()` and `shape_plot()` you can add additional ggplot objects to the plot with the `add` argument. The argument should be a named list, where the name `start` is an object to be included in the ggplot immediately after `ggplot()` (i.e. before anything else is added to the ggplot) and the name `end` will add to the end.
6363

6464
This argument can be used, for example, to add additional geoms to the plot:
6565
```{r}

0 commit comments

Comments
 (0)