label_sci | R Documentation |
This function takes the scale breaks as input and uses the
to_scientific()
function to convert the scale breaks to
formatted scientific notation.
label_sci( digits = 2, max_cut = 10^5, min_cut = 10^-3, common = FALSE, factor = NULL, trailing = TRUE, units = NULL )
digits |
Number of significant figures to display in the converted output |
max_cut |
Above this number, values will be converted into scientific format (inclusive) |
min_cut |
Below this number, values will be converted into scientific format (exclusive) |
common |
Should the formatted numbers share a common exponential factor? |
factor |
Provides a value for the common exponential factor; if |
trailing |
Should trailing zeros be included in the formatted number? |
units |
If provided, adds units to the converted output |
The labels argument of the ggplot2
scale functions can accept a character
vector providing the names or a function that takes the breaks as input and
returns the labels as output. The axis breaks cannot be accessed as a named
variable, but they are the provided input if a function is used for the
labels argument.
This setup is based on the
label_scientific()
function in the
scales
package.
Labels to use inside a scale_*() function for a ggplot2 object
library(ggplot2) df <- data.frame(x = seq(1000, 5000, by = 1000), y = 1:5) if (requireNamespace("ggplot2", quietly = TRUE)) { p <- ggplot(df, aes(x, y)) + geom_point() + scale_x_continuous(labels = label_sci(max_cut = 10)) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.