Learn R Programming

ggalign (version 1.0.1)

layer_order: Change the layer adding order

Description

This function allows you to change the order in which layers are added to a ggplot.

Usage

layer_order(layer, order = 0)

Value

A layer_order object.

Arguments

layer

A layer geometry object to be added.

order

An integer indicating the position at which the layer should be added. If <= 0, the layer will be added at the beginning. If greater than the number of plot layers, it will be added at the end.

Examples

Run this code
ggplot(faithfuld, aes(waiting, eruptions)) +
    geom_raster(aes(fill = density)) +
    geom_point(color = "red", size = 1)
ggplot(faithfuld, aes(waiting, eruptions)) +
    geom_raster(aes(fill = density)) +
    layer_order(geom_point(color = "red", size = 1))

Run the code above in your browser using DataLab