Skip to content

Commit 07ebce6

Browse files
committed
fix series of minor issues
1 parent 39765cd commit 07ebce6

File tree

7 files changed

+28
-48
lines changed

7 files changed

+28
-48
lines changed

R/plot-build.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ ggplotGrob <- function(x) {
340340
ggplot_gtable(ggplot_build(x))
341341
}
342342

343-
S7::method(as.gtable, class_ggplot) <- ggplotGrob
344-
S7::method(as.gtable, class_ggplot_built) <- ggplotGrob
343+
S7::method(as.gtable, class_ggplot) <- function(x, ...) ggplotGrob(x)
344+
S7::method(as.gtable, class_ggplot_built) <- function(x, ...) ggplotGrob(x)
345345

346346
# Apply function to layer and matching data
347347
by_layer <- function(f, layers, data, step = NULL) {

R/plot-construction.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ S7::method(`+`, list(class_ggplot, S7::class_any)) <- function(e1, e2) {
6868
add_ggplot(e1, e2, e2name)
6969
}
7070

71+
S7::method(`+`, list(theme, S7::class_any)) <- function(e1, e2) {
72+
e2name <- deparse(substitute(e2, env = caller_env(2)))
73+
add_theme(e1, e2, e2name)
74+
}
75+
7176

7277
#' @rdname gg-add
7378
#' @export
@@ -88,7 +93,6 @@ add_ggplot <- function(p, object, objectname) {
8893
#'
8994
#' @param object An object to add to the plot
9095
#' @param plot The ggplot object to add `object` to
91-
#' @param object_name The name of the object to add
9296
#'
9397
#' @return A modified ggplot object
9498
#' @details
@@ -104,19 +108,18 @@ add_ggplot <- function(p, object, objectname) {
104108
#' @keywords internal
105109
#' @export
106110
#' @examples
107-
#' # making a new method for the generic
108-
#' # in this example, we apply a text element to the text theme setting
109-
#' ggplot_add.element_text <- function(object, plot, object_name) {
110-
#' plot + theme(text = object)
111-
#' }
111+
#' S7::method(ggplot_add, list(S7::new_S3_class("element_text"), class_ggplot)) <-
112+
#' function(object, plot, ...) {
113+
#' plot + theme(text = object)
114+
#' }
112115
#'
113116
#' # we can now use `+` to add our object to a plot
114117
#' ggplot(mpg, aes(displ, cty)) +
115118
#' geom_point() +
116119
#' element_text(colour = "red")
117120
#'
118121
#' # clean-up
119-
#' rm(ggplot_add.element_text)
122+
#' rm("element_text", envir = ggplot_add@methods)
120123
ggplot_add <- S7::new_generic("ggplot_add", c("object", "plot"))
121124

122125
S7::method(ggplot_add, list(S7::class_any, class_ggplot)) <-

R/plot.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,8 @@ plot_clone <- function(plot) {
232232
#' @return Invisibly returns the original plot.
233233
#' @export
234234
#' @method print ggplot2::ggplot
235-
#' @usage
236-
#' print(x, newpage = is.null(vp), vp = NULL, ...)
237-
#' plot(x, newpage = is.null(vp), vp = NULL, ...)
235+
#' @name print.ggplot
236+
#' @aliases print.ggplot2::ggplot plot.ggplot2::ggplot
238237
#' @examples
239238
#' colours <- list(~class, ~drv, ~fl)
240239
#'
@@ -249,9 +248,7 @@ plot_clone <- function(plot) {
249248
#' print(ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) +
250249
#' geom_point())
251250
#' }
252-
`print.ggplot2::ggplot` <-
253-
S7::method(plot, class_ggplot) <-
254-
function(x, newpage = is.null(vp), vp = NULL, ...) {
251+
`print.ggplot2::ggplot` <- function(x, newpage = is.null(vp), vp = NULL, ...) {
255252
set_last_plot(x)
256253
if (newpage) grid.newpage()
257254

@@ -281,6 +278,8 @@ plot_clone <- function(plot) {
281278
invisible(x)
282279
}
283280

281+
S7::method(plot, class_ggplot) <- `print.ggplot2::ggplot`
282+
284283
#' @export
285284
`$.ggplot2::gg` <- function(x, i) {
286285
`[[`(S7::props(x), i)

R/summary.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#' Displays a useful description of a ggplot object
22
#'
3+
#' @noRd
34
#' @param object ggplot2 object to summarise
45
#' @param ... other arguments ignored (for compatibility with generic)
56
#' @keywords internal
67
#' @name summary.ggplot
8+
#' @aliases summary.ggplot summary.ggplot2::ggplot
79
#' @usage summary(object, ...)
810
#' @examples
911
#' p <- ggplot(mtcars, aes(mpg, wt)) +

man/ggplot_add.Rd

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

man/print.ggplot2-colon-colon-ggplot.Rd renamed to man/print.ggplot.Rd

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

man/summary.ggplot.Rd

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)