| Title: | Set Axis Break for 'ggplot2' |
|---|---|
| Description: | An implementation of scale functions for setting axis breaks of a 'gg' plot (S Xu (2021) <doi:10.3389/fgene.2021.774846>). |
| Authors: | Guangchuang Yu [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-6485-8781>), Shuangbin Xu [aut] (ORCID: <https://orcid.org/0000-0003-3513-5362>) |
| Maintainer: | Guangchuang Yu <[email protected]> |
| License: | Artistic-2.0 |
| Version: | 0.2.2 |
| Built: | 2026-10-09 17:19:57 UTC |
| Source: | https://github.com/yulab-smu/ggbreak |
This scale function wraps a 'gg' plot over multiple rows to make plots with long x axes easier to read.
scale_wrap(n)scale_wrap(n)
n |
the number of subplot pieces. |
A plot can be broken on both axes (scale_x_break() with scale_y_break()), but a wrapping, breaking or cutting scale cannot be combined with a different one of them.
gg object
library(ggplot2) library(ggbreak) p <- ggplot(economics, aes(x=date, y = unemploy, colour = uempmed)) + geom_line() p + scale_wrap(n=4)library(ggplot2) library(ggbreak) p <- ggplot(economics, aes(x=date, y = unemploy, colour = uempmed)) + geom_line() p + scale_wrap(n=4)
Set an axis break point for a 'gg' plot
scale_x_break( breaks, scales = "fixed", ticklabels = NULL, expand = TRUE, space = 0.1, symbol = NULL, bridge = FALSE ) scale_y_break( breaks, scales = "fixed", ticklabels = NULL, expand = TRUE, space = 0.1, symbol = NULL, bridge = FALSE )scale_x_break( breaks, scales = "fixed", ticklabels = NULL, expand = TRUE, space = 0.1, symbol = NULL, bridge = FALSE ) scale_y_break( breaks, scales = "fixed", ticklabels = NULL, expand = TRUE, space = 0.1, symbol = NULL, bridge = FALSE )
breaks |
break point. For a discrete axis these are the names of two
levels, and the levels lying strictly between them are dropped, so two
adjacent levels only insert a gap. For a date or datetime axis they may be
given as |
scales |
relative width or height of subplots, default is "fixed". If scale is 'free', all subplots have equal width or height. It also can be any number to set relative width or height compare to first subplot. |
ticklabels |
the axis labels to subplot, default is NULL. |
expand |
default is TRUE, logical or a vector of range expansion constants
used to add some padding around the data to ensure that they
are placed some distance away from the axes. Use the convenience
function |
space |
the blank space among the subplots after break, default is 0.1 (cm). |
symbol |
the break symbol, default is NULL, could be 'slash'. |
bridge |
whether to draw the piece of a line that the break hides, so
that a line crossing the break reads as one line instead of two, default is
FALSE. Only the lines of |
This scale function set an axis break point for a 'gg' plot. Either 'x' and 'y' axes are supported. The result is still a 'gg' object and user can progressively add layers to it. A plot can be broken on both axes (scale_x_break() with scale_y_break()), but a wrapping, breaking or cutting scale cannot be combined with a different one of them.
gg object
Guangchuang Yu
require(ggplot2 ) set.seed(2019-01-19) d <- data.frame( x = 1:20, y = c(rnorm(5) + 4, rnorm(5) + 20, rnorm(5) + 5, rnorm(5) + 22) ) p <- ggplot(d, aes(x, y)) + geom_col() x <- p+scale_y_break(c(7, 17 ) ) print(x)require(ggplot2 ) set.seed(2019-01-19) d <- data.frame( x = 1:20, y = c(rnorm(5) + 4, rnorm(5) + 20, rnorm(5) + 5, rnorm(5) + 22) ) p <- ggplot(d, aes(x, y)) + geom_col() x <- p+scale_y_break(c(7, 17 ) ) print(x)
scale_x_cut
scale_y_cut
scale_x_cut(breaks, which = NULL, scales = NULL, expand = FALSE, space = 0.1) scale_y_cut(breaks, which = NULL, scales = NULL, expand = FALSE, space = 0.1)scale_x_cut(breaks, which = NULL, scales = NULL, expand = FALSE, space = 0.1) scale_y_cut(breaks, which = NULL, scales = NULL, expand = FALSE, space = 0.1)
breaks |
a numeric or numeric vector, the points to be divided |
which |
integer, the position of subplots to scales, started from left to right or top to bottom. |
scales |
numeric, relative width or height of subplots. |
expand |
default is FALSE, logical a vector of range expansion constants
used to add some padding around the data to ensure that they
are placed some distance away from the axes. Use the convenience
function |
space |
the blank space among the subplots after cut, default is 0.1 (cm). |
A plot can be broken on both axes (scale_x_break() with scale_y_break()), but a wrapping, breaking or cutting scale cannot be combined with a different one of them.
gg object
library(ggplot2) library(ggbreak) set.seed(2019-01-19) d <- data.frame( x = 1:20, y = c(rnorm(5) + 4, rnorm(5) + 20, rnorm(5) + 5, rnorm(5) + 22) ) p <- ggplot(d, aes(x, y)) + geom_col() p + scale_y_cut(breaks=c(7, 18), which=c(1, 3), scales=c(3, 0.5))library(ggplot2) library(ggbreak) set.seed(2019-01-19) d <- data.frame( x = 1:20, y = c(rnorm(5) + 4, rnorm(5) + 20, rnorm(5) + 5, rnorm(5) + 22) ) p <- ggplot(d, aes(x, y)) + geom_col() p + scale_y_cut(breaks=c(7, 18), which=c(1, 3), scales=c(3, 0.5))