modify_axes: Move axis positions and match axis scales

Description Usage Arguments Examples

Description

gg_move_y_axis() moves the current y axis to the specified position. pw_match_y_axis() ensures that the y axes in a patchwork object all use the same range.

Usage

1
2
3
gg_move_y_axis(gg, position = "right")

pw_match_y_axis(pw)

Arguments

gg

Object inheriting from gg.

position

"right" or "left"

pw

Object inheriting from 'patchwork'

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
library(ggplot2)
library(dplyr)
library(patchwork)

# two plots with different y-axis ranges
p1 <- ex_pe %>%
  filter(Variable == "mead_dec_pe", ScenarioGroup == "April ST CT", 
        TraceNumber == 1) %>%
  ggplot(aes(Year, Value)) +
  geom_line()
  
p2 <- ex_pe %>%
  filter(Variable == "mead_dec_pe", ScenarioGroup == "April ST CT", 
        TraceNumber == 15) %>%
  ggplot(aes(Year, Value)) +
  scale_y_continuous(labels = scales::comma) +
  geom_line()
  
# default patchwork has two y-axes both on the left, and with different 
# ranges
print(p1 | p2)

# move the y-axis to the right side
p2 <- gg_move_y_axis(p2)

# and then match the y axis ranges
print(pw_match_y_axis(p1 | p2))

rabutler-usbr/crssplot documentation built on Feb. 6, 2022, 3:33 p.m.