scale_axis | R Documentation |
scale_axis
takes a ggplot2 object as input and applies to its x-axis
or y-axis one of the following scales:
comma . Show numbers in 000,000 format.
dollar. Show $ in front of numbers.
pct . Use percent format.
log . Use log transformation.
log1p . Use log(x+1) transformation.
log10 . Use log10 transformation.
log2 . Use log2 transformation.
sqrt . Use squared root transformation.
exp . Use exponential transformation.
date . Use date format.
If a ggplot object has too few breaks on an axis (to see the max value), and if you don't need to apply any scales to the axis (due to the values are already in a nice range), you can apply scale='default' to that axis, and this will add nticks (a number supplied by you) from the min to the max value on that axis.
scale_axis(p, axis = "y", scale = "default", nticks = 10, digits)
p |
A ggplot2 object. |
axis |
A string of value "x" or "y". Default = "y". |
scale |
A string of value "default", "comma", "dollar", "pct", "log", "log1p", "log10", "log2", "sqrt", "exp", or 'date'. |
nticks |
Number of ticks on axis. Default = 10. The actual number of ticks shown will be 1 or 2 less or more that the number user supplied depends on the actual limit of the data. This is caused by rounding in computation. |
digits |
Number of digits after the decimal point when using the 'pct' scale. Default uses best guess. It's only effective when ‘scale = ’pct''. |
A ggplot2 object with the new scale applied to the input axis.
inst/examples/ex-scale_axis.R
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.