util.plots.share.axis: combine plots and share axis

Description Usage Arguments Value Examples

View source: R/utils-plot.R

Description

modify plots by hiding x/y axes if shared x/y axis is used, plots combination is done by patchwork package.
plotlist can also be output by setting return.plots = TRUE.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
util.plots.share.axis(
  ...,
  shared.axis = "y",
  plots.theme = NULL,
  plots.coord = NULL,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  nrow = NULL,
  ncol = NULL,
  legend.position = "bottom",
  return.plots = FALSE
)

Arguments

...

ggplot objects

shared.axis

'x', 'y', defaults to 'y'

plots.theme

ggplot theme, defaults to util.lh2.theme

plots.coord

ggplot coord, defaults to coord_flip

title

str, plot global title

subtitle

str, plot global subtitle

caption

str, plot global caption

nrow

int, number of rows of the layout

ncol

int, number of ncols of the layout

legend.position

'right','left','bottom','top'

return.plots

if TRUE -> return list of plots only, defaults to FALSE

Value

ggplot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(ggplot2)
library(dplyr)
library(patchwork)

p1 <- mtcars %>%
  mutate(gear = factor(gear), am = factor(am)) %>%
  util.plot.stack.bar('gear','am') +
  labs(title = 'p1')
p2 <- mtcars %>%
  mutate(am = factor(gear)) %>%
  group_by(am) %>%
  summarise(n = n()) %>%
  ggplot(aes(x = am, y = n)) +
  geom_bar(stat = 'identity', fill = util.lh2.fill('orange'))+
  labs(title = 'p2')
  
util.plots.share.axis(p1, p2, 
  title = 'Shared Axis Plot')

6chaoran/lh2util documentation built on Nov. 29, 2020, 1:28 a.m.