Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

get_y_axis

Get plot axes


Description

These functions extract just the axes from a ggplot. get_y_axis() pulls the y-axis, while get_x_axis() pulls the x-axis.

Usage

get_y_axis(plot, position = c("left", "right"))

get_x_axis(plot, position = c("bottom", "top"))

Arguments

plot

A ggplot or gtable.

position

Which side of the plot is the axis on? For the x-axis, this can be "top" or "bottom", and for the y-axis, it can be "left" or "right".

Examples

library(ggplot2)

p <- ggplot(mpg, aes(displ, cty)) +
  geom_point()

ggdraw(get_y_axis(p))
p <- p + scale_x_continuous(position = "top")
ggdraw(get_x_axis(p, position = "top"))

cowplot

Streamlined Plot Theme and Plot Annotations for 'ggplot2'

v1.1.1
GPL-2
Authors
Claus O. Wilke [aut, cre] (<https://orcid.org/0000-0002-7470-9261>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.