Learn R Programming

lemon (version 0.4.9)

brackets_horizontal: Axis brackets instead of axis ticks and lines

Description

To be used with coord_flex_cart, coord_capped_cart, etc. for displaying brackets instead of the axis ticks and lines.

Usage

brackets_horizontal(
  direction = c("up", "down"),
  length = unit(0.05, "npc"),
  tick.length = waiver()
)

brackets_vertical( direction = c("left", "right"), length = unit(0.05, "npc"), tick.length = waiver() )

Arguments

direction

Which way should the opening side of the brackets point? up, down, left, or right?

length

Length of the unit, parallel with axis line.

tick.length

Height (width) of x-axis (y-axis) bracket. If waiver() (default), use axis.ticks.length from theme.

Details

The looks of the brackets are taken from theme(axis.ticks), or theme(axis.ticks.x) and theme(axis.ticks.y), respectively.

It does not re-calculate tick marks, but lets scale_x_* and scale_y_* calculate and draw ticks and labels, and then modifies the ticks with brackets.

Both length and tick.length accepts a numeric scalar instead of a unit object that is interpreted as an "npc" unit.

See Also

Examples

Run this code
library(ggplot2)
p <- ggplot(mpg, aes(as.factor(cyl), hwy, colour=class)) +
  geom_point(position=position_jitter(width=0.3)) +
  theme_bw() +
  theme(panel.border = element_blank(), axis.line = element_line())
p

p <- p + coord_flex_cart(bottom=brackets_horizontal(length=unit(0.08, 'npc')))
p
# However getting the correct width is a matter of tweaking either length or
# position_jitter...

# A further adjustment,
p + theme(panel.grid.major.x = element_blank())

Run the code above in your browser using DataLab