Learn R Programming

ggh4x (version 0.3.0)

strip_tag: Strips as tags

Description

This strip style renders the strips as text with fitted boxes onto the panels of the plot. This is in contrast to strips that match the panel size and are located outside the panels.

Usage

strip_tag(
  clip = "inherit",
  order = c("x", "y"),
  just = c(0, 1),
  text_x = NULL,
  text_y = element_text(angle = 0),
  background_x = NULL,
  background_y = NULL,
  by_layer_x = FALSE,
  by_layer_y = FALSE
)

Value

A StripTag ggproto object that can be given as an argument to facets in ggh4x.

Arguments

clip

A character(1) that controls whether text labels are clipped to the background boxes. Can be either "inherit" (default), "on" or "off".

order

Either c("x", "y") or c("y", "x"), setting the top-to-bottom order of horizontal versus "vertical" labels in facets with a grid layout.

just

A <numeric[2]> setting the horizontal and vertical justification of placing the textbox.

text_x, text_y

A list() with element_text() elements. See details.

background_x, background_y

A list() with element_rect() elements. See details.

by_layer_x, by_layer_y

A logical(1) that when TRUE, maps the different elements to different layers of the strip. When FALSE, maps the different elements to individual strips, possibly repeating the elements to match the number of strips through rep_len().

See Also

Other strips: strip_nested(), strip_split(), strip_themed(), strip_vanilla()

Examples

Run this code
# A standard plot
p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()

# Typical use
p + facet_wrap2(
  ~ class,
  strip = strip_tag()
)

# Adjusting justification
p + facet_wrap2(
  ~ class,
  strip = strip_tag(just = c(1, 0))
)

p + facet_wrap2(
  ~ drv + year,
  strip = strip_tag()
)

# With a grid layout, you can control in which order the labels are drawn
p + facet_grid2(
  "vertical" ~ "horizontal",
  strip = strip_tag(order = c("x", "y")) # default
)

p +facet_grid2(
  "vertical" ~ "horizontal",
  strip = strip_tag(order = c("y", "x")) # invert order
)

Run the code above in your browser using DataLab