Description Usage Arguments Value Author(s) Examples
Intended to be used as a hack to get different y-axes breaks.
1 2 | shift_column(.data, value_col, facet_col, fun = function(v) range(v, na.rm =
TRUE))
|
.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). |
A list of two elements:
A data frame with shifted data.
A data frame with the mapping between original and shifted breaks.
Christofer Bäcklin
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.