shift_column: Groupwise shift the values of a column to make their ranges...

Description Usage Arguments Value Author(s) Examples

Description

Intended to be used as a hack to get different y-axes breaks.

Usage

1
2
shift_column(.data, value_col, facet_col, fun = function(v) range(v, na.rm =
  TRUE))

Arguments

.data

Data frame.

value_col

Name of the column to shift.

facet_col

Name of the column that will later be used for faceting.

fun

Function that produce axis breaks. If you wish to add more breaks please do so by manipulating the return value (2nd element).

Value

A list of two elements:

Author(s)

Christofer B├Ącklin

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
library(ggplot2)

break_fun <- function(v){
	c(mean(v), range(v))
}

shifted_cars <- shift_column(mtcars, "mpg", facet_col = "cyl", fun = break_fun)

plot_data <- shifted_cars[[1]]
mapping <- shifted_cars[[2]]

ggplot(plot_data, aes(x = disp, y = mpg)) +
  facet_wrap(~cyl, scales = "free_y") +
  geom_point() +
  scale_y_continuous(
    breaks = mapping$breaks,
    labels = numeric_label(mapping$labels),
    expand = c(0, 0)
  ) +
	line_theme(box = TRUE, grid = "y")

backlin/treesmapstheorems documentation built on May 11, 2019, 5:23 p.m.