label_skip | R Documentation |
Creates a labeller function that removes every n-th label on an ggplot2
axis.
Useful for reducing overlapping labels while keeping the major ticks.
label_skip(n = 2, start = "left", labeller = NULL)
n |
Integer. Display every nth label. Default is |
start |
Where to start the pattern. Either |
labeller |
Optional function to transform labels before applying skip pattern.
For example |
A function that takes a vector of labels and returns a vector with skipped labels replaced by empty strings.
library(ggplot2)
# Default skip labels
ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point() +
scale_x_continuous(labels = label_skip())
# Skip date labels, while keep ticks
ggplot(economics, aes(x = date, y = unemploy)) +
geom_line() +
scale_x_date(
date_breaks = "2 years",
labels = label_skip(start = "right", labeller = label_date(format = "%Y"))
) +
theme_bw()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.