|
47 | 47 | #' @param quiet Set to TRUE to not print the plot nor show generated code in the RStudio 'Viewer' pane. (Default: FALSE)
|
48 | 48 | #' @param printplot Print the plot. (Default: !quiet)
|
49 | 49 | #' @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. |
56 | 52 | #' @param envir Environment in which to evaluate the plot code. May be useful when calling this function inside another function.
|
57 | 53 | #'
|
58 | 54 | #' @return A list:
|
@@ -107,10 +103,9 @@ shape_plot <- function(data,
|
107 | 103 | quiet = FALSE,
|
108 | 104 | printplot = !quiet,
|
109 | 105 | showcode = !quiet,
|
110 |
| - addcode = NULL, |
111 | 106 | addaes = NULL,
|
112 | 107 | addarg = NULL,
|
113 |
| - addlayer = NULL, |
| 108 | + add = NULL, |
114 | 109 | envir = NULL){
|
115 | 110 |
|
116 | 111 | # Check arguments ----
|
@@ -348,10 +343,10 @@ shape_plot <- function(data,
|
348 | 343 |
|
349 | 344 | indent(2,
|
350 | 345 |
|
351 |
| - # addlayer$start |
352 |
| - if (!is.null(addlayer$start)){ |
| 346 | + # add$start |
| 347 | + if (!is.null(add$start)){ |
353 | 348 | c("# Additional layer",
|
354 |
| - paste(c(deparse(substitute(addlayer)$start), " +"), collapse = ""), |
| 349 | + paste(c(deparse(substitute(add)$start), " +"), collapse = ""), |
355 | 350 | "")
|
356 | 351 | },
|
357 | 352 |
|
@@ -435,25 +430,18 @@ shape_plot <- function(data,
|
435 | 430 | plotcolour)),
|
436 | 431 |
|
437 | 432 | # theme
|
438 |
| - indent(2, shape.theme(legend.position, addlayer)), |
| 433 | + indent(2, shape.theme(legend.position, add)), |
439 | 434 |
|
440 |
| - # addlayer$end |
441 |
| - if (!is.null(addlayer$end)){ |
| 435 | + # add$end |
| 436 | + if (!is.null(add$end)){ |
442 | 437 | c("# Additional layer",
|
443 |
| - paste(deparse(substitute(addlayer)$end), collapse = ""), |
| 438 | + paste(deparse(substitute(add)$end), collapse = ""), |
444 | 439 | "")
|
445 | 440 | }
|
446 | 441 |
|
447 | 442 | )
|
448 | 443 |
|
449 | 444 |
|
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 |
| - |
457 | 445 |
|
458 | 446 | # Show code in RStudio viewer.
|
459 | 447 | if (showcode){ displaycode(plotcode) }
|
|
0 commit comments