Description Usage Arguments Examples
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.
1 2 3 | gg_move_y_axis(gg, position = "right")
pw_match_y_axis(pw)
|
gg |
Object inheriting from |
position |
"right" or "left" |
pw |
Object inheriting from 'patchwork' |
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.