Scales and guides API
On this page
- scale()
-
Functions
- scale_color_manual()
- scale_fill_manual()
- scale_color_scheme()
- scale_fill_scheme()
- scale_color_viridis()
- scale_fill_viridis()
- scale_color_brewer()
- scale_fill_brewer()
- scale_color_gradient()
- scale_fill_gradient()
- scale_color_gradient2()
- scale_fill_gradient2()
- viridis_scheme()
- brewer_scheme()
- scale_color_viridis_d()
- scale_fill_viridis_d()
- scale_color_viridis_c()
- scale_fill_viridis_c()
- scale_color_viridis_b()
- scale_fill_viridis_b()
- scale_color_distiller()
- scale_fill_distiller()
- scale_color_fermenter()
- scale_fill_fermenter()
- scale_color_gradientn()
- scale_fill_gradientn()
- scale_color_grey()
- scale_fill_grey()
- scale_color_hue()
- scale_fill_hue()
- scale_color_identity()
- scale_x_discrete()
- scale_y_discrete()
- guides()
- guide_legend()
- guide_colorbar()
- guide_colourbar()
- guide_axis()
- guide_none()
- label_number()
- label_comma()
- label_percent()
- label_dollar()
- label_scientific()
- label_date()
- xlim()
- ylim()
Examples
Scale methods set the domain, range, transformation, labels, and guide of one aesthetic. Scales, coordinates, and labels shows them with examples.
Methods: scale() · scaleX() · scaleY() · scaleColor() · scaleFill() · scaleSize() · scaleShape() · scaleOpacity() · scaleLinetype() · guides() · xlim() · ylim()
Functions: scale_x() · scale_y() · scale_x_continuous() · scale_y_continuous() · scale_x_log10() · scale_y_log10() · scale_x_sqrt() · scale_y_sqrt() · scale_x_reverse() · scale_y_reverse() · scale_x_date() · scale_y_date() · scale_color() · scale_fill() · scale_size() · scale_shape() · scale_alpha() · scale_linetype() · scale_color_manual() · scale_fill_manual() · scale_color_scheme() · scale_fill_scheme() · scale_color_viridis() · scale_fill_viridis() · scale_color_brewer() · scale_fill_brewer() · scale_color_gradient() · scale_fill_gradient() · scale_color_gradient2() · scale_fill_gradient2() · viridis_scheme() · brewer_scheme() · scale_color_viridis_d() · scale_fill_viridis_d() · scale_color_viridis_c() · scale_fill_viridis_c() · scale_color_viridis_b() · scale_fill_viridis_b() · scale_color_distiller() · scale_fill_distiller() · scale_color_fermenter() · scale_fill_fermenter() · scale_color_gradientn() · scale_fill_gradientn() · scale_color_grey() · scale_fill_grey() · scale_color_hue() · scale_fill_hue() · scale_color_identity() · scale_fill_identity() · scale_x_discrete() · scale_y_discrete() · guides() · guide_legend() · guide_colorbar() · guide_colourbar() · guide_axis() · guide_none() · label_number() · label_comma() · label_percent() · label_dollar() · label_scientific() · label_date() · xlim() · ylim()
scale()
->scale(string $aesthetic, mixed ...$options): PlotSets the scale for an aesthetic; see Scale::make() for the options.
scaleX()
->scaleX(mixed ...$options): Plotx scale: type (linear, log, sqrt, time, …), domain, range, zero, nice, reverse, name, breaks, labels, format.
Functions: scale_x(), scale_x_continuous(), scale_x_log10(), scale_x_sqrt(), scale_x_reverse(), scale_x_date(), scale_x_discrete().
scaleY()
->scaleY(mixed ...$options): PlotScale and guide options for y, as scaleX() takes them.
Functions: scale_y(), scale_y_continuous(), scale_y_log10(), scale_y_sqrt(), scale_y_reverse(), scale_y_date(), scale_y_discrete().
scaleColor()
->scaleColor(mixed ...$options): PlotColor scale: scheme (‘viridis’, ‘blues’, ‘category10’, …), range, values (manual palette), domainMid, …
Functions: scale_color(), scale_color_manual(), scale_color_scheme(), scale_color_viridis(), scale_color_brewer(), scale_color_gradient(), scale_color_gradient2(), scale_color_viridis_d(), scale_color_viridis_c(), scale_color_viridis_b(), scale_color_distiller(), scale_color_fermenter(), scale_color_gradientn(), scale_color_grey(), scale_color_hue(), scale_color_identity().
scaleFill()
->scaleFill(mixed ...$options): PlotScale and guide options for fill, as scaleColor() takes them.
Functions: scale_fill(), scale_fill_manual(), scale_fill_scheme(), scale_fill_viridis(), scale_fill_brewer(), scale_fill_gradient(), scale_fill_gradient2(), scale_fill_viridis_d(), scale_fill_viridis_c(), scale_fill_viridis_b(), scale_fill_distiller(), scale_fill_fermenter(), scale_fill_gradientn(), scale_fill_grey(), scale_fill_hue(), scale_fill_identity().
scaleSize()
->scaleSize(mixed ...$options): PlotScale and guide options for size: range sets the smallest and largest areas in square pixels.
Function: scale_size().
scaleShape()
->scaleShape(mixed ...$options): PlotScale and guide options for shape: values sets the shapes, by level or in level order.
Function: scale_shape().
scaleOpacity()
->scaleOpacity(mixed ...$options): PlotScale and guide options for opacity (alpha): range sets the lowest and highest opacity.
Function: scale_alpha().
scaleLinetype()
->scaleLinetype(mixed ...$options): PlotScale and guide options for linetype: values sets the dash patterns, by level or in level order.
Function: scale_linetype().
guides()
->guides(mixed ...$guides): PlotGuides per aesthetic, as ggplot2’s guides(): ‘none’ or false hides one, and an array sets axis or legend properties (see guide_legend(), guide_colorbar(), and guide_axis()).
Function: guides().
xlim()
->xlim(string|int|float $min, string|int|float $max): PlotFixes the x domain. Unlike ggplot2’s xlim(), data outside it is clipped rather than dropped.
Function: xlim().
ylim()
->ylim(string|int|float $min, string|int|float $max): PlotFixes the y domain. Unlike ggplot2’s ylim(), data outside it is clipped rather than dropped.
Function: ylim().
Functions
scale_color_manual()
scale_color_manual(array $values, mixed ...$args): ClosureManual colors: a level => color map, or colors in level order.
scale_fill_manual()
scale_fill_manual(array $values, mixed ...$args): ClosureThe scale_color_manual() scale for the fill aesthetic.
scale_color_scheme()
scale_color_scheme(string $scheme, mixed ...$args): ClosureVega color schemes by name, such as ‘viridis’, ‘blues’, ‘set2’, ‘dark2’, ‘tableau10’.
scale_fill_scheme()
scale_fill_scheme(string $scheme, mixed ...$args): ClosureThe scale_color_scheme() scale for the fill aesthetic.
scale_color_viridis()
scale_color_viridis(string $option = 'viridis', mixed ...$args): ClosureA viridisLite palette by Vega scheme name, such as ‘viridis’, ‘magma’, or ‘cividis’.
scale_fill_viridis()
scale_fill_viridis(string $option = 'viridis', mixed ...$args): ClosureThe scale_color_viridis() scale for the fill aesthetic.
scale_color_brewer()
scale_color_brewer(string $palette = 'set1', mixed ...$args): ClosureA ColorBrewer palette for discrete data, as ggplot2’s scale_colour_brewer (names are case-insensitive).
scale_fill_brewer()
scale_fill_brewer(string $palette = 'set1', mixed ...$args): ClosureThe scale_color_brewer() scale for the fill aesthetic.
scale_color_gradient()
scale_color_gradient( string $low = '#132B43', string $high = '#56B1F7', mixed ...$args,): ClosureA two-color gradient, as ggplot2’s scale_colour_gradient (defaults #132B43 to #56B1F7).
scale_fill_gradient()
scale_fill_gradient( string $low = '#132B43', string $high = '#56B1F7', mixed ...$args,): ClosureThe scale_color_gradient() scale for the fill aesthetic.
scale_color_gradient2()
scale_color_gradient2( string $low = '#832424', string $mid = '#FFFFFF', string $high = '#3A3A98', int|float $midpoint = 0, mixed ...$args,): ClosureA diverging gradient through mid at midpoint, as ggplot2’s scale_colour_gradient2.
scale_fill_gradient2()
scale_fill_gradient2( string $low = '#832424', string $mid = '#FFFFFF', string $high = '#3A3A98', int|float $midpoint = 0, mixed ...$args,): ClosureThe scale_color_gradient2() scale for the fill aesthetic.
viridis_scheme()
viridis_scheme( string $option = 'D', float $begin = 0.0, float $end = 1.0, int $direction = 1,): arrayviridisLite palettes by option: A magma, B inferno, C plasma, D viridis, E cividis, H turbo (or the names).
brewer_scheme()
brewer_scheme(string $palette, int $direction = 1): array|stringA ColorBrewer scheme, reversed when direction is -1.
scale_color_viridis_d()
scale_color_viridis_d( string $option = 'D', float $begin = 0.0, float $end = 1.0, int $direction = 1, mixed ...$args,): Closureviridis for discrete (_d), continuous (_c), and binned (b) scales, as ggplot2’s scale_colour_viridis*.
scale_fill_viridis_d()
scale_fill_viridis_d( string $option = 'D', float $begin = 0.0, float $end = 1.0, int $direction = 1, mixed ...$args,): ClosureThe scale_color_viridis_d() scale for the fill aesthetic.
scale_color_viridis_c()
scale_color_viridis_c( string $option = 'D', float $begin = 0.0, float $end = 1.0, int $direction = 1, mixed ...$args,): ClosureThe pipe form of ->scaleColor().
scale_fill_viridis_c()
scale_fill_viridis_c( string $option = 'D', float $begin = 0.0, float $end = 1.0, int $direction = 1, mixed ...$args,): ClosureThe scale_color_viridis_c() scale for the fill aesthetic.
scale_color_viridis_b()
scale_color_viridis_b( string $option = 'D', float $begin = 0.0, float $end = 1.0, int $direction = 1, mixed ...$args,): ClosureThe pipe form of ->scaleColor().
scale_fill_viridis_b()
scale_fill_viridis_b( string $option = 'D', float $begin = 0.0, float $end = 1.0, int $direction = 1, mixed ...$args,): ClosureThe scale_color_viridis_b() scale for the fill aesthetic.
scale_color_distiller()
scale_color_distiller( string $palette = 'Blues', int $direction = -1, mixed ...$args,): ClosureColorBrewer for continuous data, as ggplot2’s scale_colour_distiller (reversed by default, as there).
scale_fill_distiller()
scale_fill_distiller( string $palette = 'Blues', int $direction = -1, mixed ...$args,): ClosureThe scale_color_distiller() scale for the fill aesthetic.
scale_color_fermenter()
scale_color_fermenter( string $palette = 'Blues', int $direction = -1, mixed ...$args,): ClosureColorBrewer for binned continuous data, as ggplot2’s scale_colour_fermenter.
scale_fill_fermenter()
scale_fill_fermenter( string $palette = 'Blues', int $direction = -1, mixed ...$args,): ClosureThe scale_color_fermenter() scale for the fill aesthetic.
scale_color_gradientn()
scale_color_gradientn(array $colors, mixed ...$args): ClosureA gradient through several colors, as ggplot2’s scale_colour_gradientn.
scale_fill_gradientn()
scale_fill_gradientn(array $colors, mixed ...$args): ClosureThe scale_color_gradientn() scale for the fill aesthetic.
scale_color_grey()
scale_color_grey(float $start = 0.2, float $end = 0.8, mixed ...$args): ClosureGrays for discrete data, as ggplot2’s scale_colour_grey (computed for the number of levels).
scale_fill_grey()
scale_fill_grey(float $start = 0.2, float $end = 0.8, mixed ...$args): ClosureThe scale_color_grey() scale for the fill aesthetic.
scale_color_hue()
scale_color_hue( array $h = [0 => 15,1 => 375], int|float $c = 100, int|float $l = 65, int|float $hStart = 0, int $direction = 1, mixed ...$args,): Closureggplot2’s hue palette with its options, as scale_colour_hue (computed for the number of levels).
scale_fill_hue()
scale_fill_hue( array $h = [0 => 15,1 => 375], int|float $c = 100, int|float $l = 65, int|float $hStart = 0, int $direction = 1, mixed ...$args,): ClosureThe scale_color_hue() scale for the fill aesthetic.
scale_color_identity()
scale_color_identity(mixed ...$args): ClosureThe data values are the colors (or sizes, or shapes) themselves, with no legend, as ggplot2’s scale_*_identity.
scale_x_discrete()
scale_x_discrete(?array $limits = null, mixed ...$args): ClosureDiscrete position scales: limits orders (and subsets) the levels, labels renames them.
scale_y_discrete()
scale_y_discrete(?array $limits = null, mixed ...$args): ClosureThe scale_x_discrete() scale for the y axis.
guides()
guides(mixed ...$guides): ClosureAxis or legend options per aesthetic, as ggplot2’s guides(): guides(color: ‘none’, x: guide_axis(angle: 45)).
guide_legend()
guide_legend( ?string $title = null, ?int $ncol = null, ?string $direction = null, mixed ...$properties,): arrayLegend options: title, columns (ncol), direction (horizontal or vertical), and further Vega-Lite legend properties.
guide_colorbar()
guide_colorbar( ?string $title = null, int|float|null $barwidth = null, int|float|null $barheight = null, ?string $direction = null, mixed ...$properties,): arrayColor bar options: barwidth and barheight in pixels.
guide_colourbar()
guide_colourbar(mixed ...$args): arrayAn alias of guide_colorbar().
guide_axis()
guide_axis( ?string $title = null, int|float|null $angle = null, ?string $position = null, mixed ...$properties,): arrayAxis options: angle turns the labels anticlockwise, as ggplot2’s guide_axis(angle =); position is top, bottom, left, or right.
guide_none()
guide_none(): boolHides a guide, as ggplot2’s guide_none(): guides(color: guide_none()).
label_number()
label_number( int|float|null $accuracy = null, int|float $scale = 1, string $prefix = '', string $suffix = '', string $bigMark = ',',): LabelNumber labels, as scales::label_number(): accuracy rounds, scale multiplies, prefix and suffix wrap.
label_comma()
label_comma( int|float|null $accuracy = null, int|float $scale = 1, string $prefix = '', string $suffix = '',): LabelThousands separators, as scales::label_comma().
label_percent()
label_percent( int|float|null $accuracy = null, int|float $scale = 100, string $prefix = '', string $suffix = '%',): LabelPercentages of proportions, as scales::label_percent(): 0.25 becomes 25%.
label_dollar()
label_dollar( int|float|null $accuracy = null, int|float $scale = 1, string $prefix = '$', string $suffix = '',): LabelCurrency, as scales::label_dollar().
label_scientific()
label_scientific(int $digits = 3): LabelScientific notation with digits significant digits, as scales::label_scientific().
label_date()
label_date(string $format = '%Y-%m-%d'): LabelDates and times with a strftime-style format, as scales::label_date().
xlim()
xlim(string|int|float $min, string|int|float $max): ClosureThe pipe form of ->xlim().
ylim()
ylim(string|int|float $min, string|int|float $max): ClosureThe pipe form of ->ylim().