Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 77 lines (64 sloc) 2.08 kB
a7f3c10 @hadley Convert facets to S3
authored
1 #' Facet specification: a single panel.
2 #'
9d3d8e8 @hadley Better documentation for facets
authored
3 #' @inheritParams facet_grid
a7f3c10 @hadley Convert facets to S3
authored
4 #' @export
5 #' @examples
1244716 @hadley Trim whitespace
authored
6 #' # facet_null is the default facetting specification if you
a7f3c10 @hadley Convert facets to S3
authored
7 #' # don't override it with facet_grid or facet_wrap
8 #' ggplot(mtcars, aes(mpg, wt)) + geom_point()
3bc0b7e @hadley Test that shrink parameter works
authored
9 facet_null <- function(shrink = TRUE) {
10 facet(shrink = shrink, subclass = "null")
a7f3c10 @hadley Convert facets to S3
authored
11 }
a4c8511 @hadley Copy over all new files
authored
12
3c63ff7 @hadley Convert from @S3method to @export
authored
13 #' @export
1244716 @hadley Trim whitespace
authored
14 facet_train_layout.null <- function(facet, data) {
a7f3c10 @hadley Convert facets to S3
authored
15 data.frame(
1244716 @hadley Trim whitespace
authored
16 PANEL = 1L, ROW = 1L, COL = 1L,
a7f3c10 @hadley Convert facets to S3
authored
17 SCALE_X = 1L, SCALE_Y = 1L)
18 }
a4c8511 @hadley Copy over all new files
authored
19
3c63ff7 @hadley Convert from @S3method to @export
authored
20 #' @export
c093bc8 @hadley Single row/col facetting working
authored
21 facet_map_layout.null <- function(facet, data, layout) {
9b37e42 @wch Clean up for empty data
wch authored
22 # Need the is.waive check for special case where no data, but aesthetics
bbfc5be @hrbrmstr finished removing qplot from remaining functions except for the expli…
hrbrmstr authored
23 # are mapped to vectors
9b37e42 @wch Clean up for empty data
wch authored
24 if (is.waive(data) || empty(data))
25 return(cbind(data, PANEL = integer(0)))
3e98dbc @kohske Fix a bug in facet-null layout mapping when unusual column name (e.g.…
kohske authored
26 data$PANEL <- 1L
27 data
a7f3c10 @hadley Convert facets to S3
authored
28 }
a4c8511 @hadley Copy over all new files
authored
29
3c63ff7 @hadley Convert from @S3method to @export
authored
30 #' @export
76db69e @hadley Plot with facet_null runs without errors
authored
31 facet_render.null <- function(facet, panel, coord, theme, geom_grobs) {
32 range <- panel$ranges[[1]]
1244716 @hadley Trim whitespace
authored
33
76db69e @hadley Plot with facet_null runs without errors
authored
34 # Figure out aspect ratio
1487e01 @wch Convert coords to ggproto
wch authored
35 aspect_ratio <- theme$aspect.ratio %||% coord$aspect(range)
a7f3c10 @hadley Convert facets to S3
authored
36 if (is.null(aspect_ratio)) {
37 aspect_ratio <- 1
38 respect <- FALSE
39 } else {
40 respect <- TRUE
a4c8511 @hadley Copy over all new files
authored
41 }
1244716 @hadley Trim whitespace
authored
42
1487e01 @wch Convert coords to ggproto
wch authored
43 fg <- coord$render_fg(range, theme)
44 bg <- coord$render_bg(range, theme)
a4c8511 @hadley Copy over all new files
authored
45
76db69e @hadley Plot with facet_null runs without errors
authored
46 # Flatten layers - we know there's only one panel
47 geom_grobs <- lapply(geom_grobs, "[[", 1)
2e722cc @noamross New theme option to put panel/grid on top of data
noamross authored
48
ec3cd49 @hadley Processing RStudio diagnostics
authored
49 if (theme$panel.ontop) {
2e722cc @noamross New theme option to put panel/grid on top of data
noamross authored
50 panel_grobs <- c(geom_grobs, list(bg), list(fg))
51 } else {
52 panel_grobs <- c(list(bg), geom_grobs, list(fg))
53 }
1244716 @hadley Trim whitespace
authored
54
55 panel_grob <- gTree(children = do.call("gList", panel_grobs))
1487e01 @wch Convert coords to ggproto
wch authored
56 axis_h <- coord$render_axis_h(range, theme)
57 axis_v <- coord$render_axis_v(range, theme)
1244716 @hadley Trim whitespace
authored
58
a7f3c10 @hadley Convert facets to S3
authored
59 all <- matrix(list(
60 axis_v, panel_grob,
61 zeroGrob(), axis_h
16c0e55 @hadley More example fixes
authored
62 ), ncol = 2, byrow = TRUE)
1244716 @hadley Trim whitespace
authored
63
c7cb1bf @wch Remove utilities-table-template.r and migrate to gtable package
wch authored
64 layout <- gtable_matrix("layout", all,
a7f3c10 @hadley Convert facets to S3
authored
65 widths = unit.c(grobWidth(axis_v), unit(1, "null")),
39f2c70 @hadley Make sure facet_null uses correct aspect ratio
authored
66 heights = unit.c(unit(aspect_ratio, "null"), grobHeight(axis_h)),
2741063 @wch Both axis lines draw above panel
wch authored
67 respect = respect, clip = c("off", "off", "on", "off"),
68 z = matrix(c(3, 2, 1, 4), ncol = 2, byrow = TRUE)
a7f3c10 @hadley Convert facets to S3
authored
69 )
56e329c @hadley Draw title, axis labels and margins with gtable
authored
70 layout$layout$name <- c("axis-l", "spacer", "panel", "axis-b")
1244716 @hadley Trim whitespace
authored
71
76db69e @hadley Plot with facet_null runs without errors
authored
72 layout
a7f3c10 @hadley Convert facets to S3
authored
73 }
c6c9a2c @hadley Add facet print method so summary works.
authored
74
3c63ff7 @hadley Convert from @S3method to @export
authored
75 #' @export
c6c9a2c @hadley Add facet print method so summary works.
authored
76 facet_vars.null <- function(facet) ""
Something went wrong with that request. Please try again.