Learn R Programming

cowplot (version 0.5.0)

switch_axis_position: Switches the axis position of the x or y axis in a ggplot2 plot.

Description

Switches the axis position of the x or y axis in a ggplot2 plot.

Usage

switch_axis_position(plot, axis = c("y", "x", "xy"), keep = c("none", "x",
  "y", "xy", "yx"))

Arguments

plot
The plot on which to perform the operation.
axis
String indicating which axis to switch. Valid options are"x", "y", and "xy". The default is "y".
keep
String indicating which if any original axis to keep. Valid options are"x", "y", "xy", and "none". The default is "none".

Value

  • A gtable object (not ggplot object!) on which the axes have been switched.

Examples

Run this code
p <- ggplot(mtcars, aes(mpg, disp)) + geom_line(colour = "blue")
ggdraw(switch_axis_position(p, axis = 'y'))
ggdraw(switch_axis_position(p, axis = 'x'))
ggdraw(switch_axis_position(p + theme_bw(), axis = 'xy', keep = 'x'))

Run the code above in your browser using DataLab