Skip to content
Browse files

Add facet print method so summary works.

Fixes #213
  • Loading branch information...
1 parent f69e85c commit c6c9a2c36b060b0ab91f059c903abddd8005d84b @hadley committed
Showing with 29 additions and 1 deletion.
  1. +17 −0 R/facet-.r
  2. +5 −0 R/facet-grid-.r
  3. +2 −0 R/facet-null.r
  4. +4 −0 R/facet-wrap.r
  5. +1 −1 R/summary.r
View
17 R/facet-.r
@@ -43,3 +43,20 @@ facet_panels <- function(facet, panel, coord, theme, geom_grobs)
facet_axes <- function(facet, panel, coord, theme)
UseMethod("facet_axes")
+
+# Text description of facetting variables
+facet_vars <- function(facet)
+ UseMethod("facet_vars")
+
+
+#' @S3method format facet
+format.facet <- function(x, ...) {
+ name <- paste(rev(class(x)), collapse = "_")
+
+ paste(name, "(", facet_vars(x), ")", sep = "")
+}
+
+#' @S3method print facet
+print.facet <- function(x, ...) {
+ cat(format(x, ...), "\n")
+}
View
5 R/facet-grid-.r
@@ -321,3 +321,8 @@ icon.grid <- function(.) {
segmentsGrob(c(0, 0.475), c(0.475, 0), c(1, 0.475), c(0.475, 1))
))
}
+
+facet_vars.grid <- function(facet) {
+ paste(lapply(list(facet$rows, facet$cols), paste, collapse = ", "),
+ collapse = " ~ ")
+}
View
2 R/facet-null.r
@@ -69,3 +69,5 @@ icon.facet_null <- function(.) {
segmentsGrob(c(0, 0.475), c(0.475, 0), c(1, 0.475), c(0.475, 1))
))
}
+
+facet_vars.null <- function(facet) ""
View
4 R/facet-wrap.r
@@ -223,3 +223,7 @@ facet_axes.wrap <- function(facet, panel, coord, theme) {
axes
}
+
+facet_vars.wrap <- function(facet) {
+ paste(lapply(facet$facets, paste, collapse = ", "), collapse = " ~ ")
+}
View
2 R/summary.r
@@ -32,7 +32,7 @@ summary.ggplot <- function(object, ...) {
}
cat("faceting: ")
- object$facet$pprint()
+ print(object$facet)
if (length(object$layers) > 0)
cat("-----------------------------------\n")

0 comments on commit c6c9a2c

Please sign in to comment.
Something went wrong with that request. Please try again.