File: summary.R

package info (click to toggle)
r-cran-ggplot2 3.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 9,944 kB
  • sloc: sh: 15; makefile: 5
file content (42 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download | duplicates (5)
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
#' Displays a useful description of a ggplot object
#'
#' @param object ggplot2 object to summarise
#' @param ... other arguments ignored (for compatibility with generic)
#' @keywords internal
#' @method summary ggplot
#' @export
#' @examples
#' p <- ggplot(mtcars, aes(mpg, wt)) +
#'   geom_point()
#' summary(p)
summary.ggplot <- function(object, ...) {
  wrap <- function(x) paste(
    paste(strwrap(x, exdent = 2), collapse = "\n"),
    "\n", sep = ""
    )

  if (!is.null(object$data)) {
    output <- paste(
      "data:     ", paste(names(object$data), collapse = ", "),
      " [", nrow(object$data), "x", ncol(object$data), "] ",
      "\n", sep = "")
    cat(wrap(output))
  }
  if (length(object$mapping) > 0) {
    cat("mapping:  ", clist(object$mapping), "\n", sep = "")
  }
  if (object$scales$n() > 0) {
    cat("scales:  ", paste(object$scales$input(), collapse = ", "), "\n")
  }

  cat("faceting: ")
  print(object$facet)

  if (length(object$layers) > 0)
    cat("-----------------------------------\n")
  invisible(lapply(object$layers, function(x) {
    print(x)
    cat("\n")
  }))

}