sm_put_together: Combining figures together

View source: R/sm_put_together.R

sm_put_togetherR Documentation

Combining figures together

Description

This function works best if all_plots argument (the list input) contains plots that have tick labels on both x and y axes; this information will be used to optimize the layout of the composite figure.

Usage

sm_put_together(
  all_plots,
  title,
  xlabel,
  ylabel,
  legend,
  ncol,
  nrow,
  xlabel2,
  ylabel2,
  tickRatio,
  panel_scale = 0.9,
  wRatio,
  hRatio,
  hmargin = 0,
  wmargin = 0,
  remove_ticks = "some",
  wRatio2,
  hRatio2,
  labelRatio = 1
)

Arguments

all_plots

all_plots should be list, which should contain all panels that are to be combined into one figure.

title

Title layer that will determine the main title of the combined plot. This is created using sm_common_title(). Optional argument. Users can also supply character string here instead.

xlabel

xlabel layer that will determine the label of the combined plot's x-axis. This is created using sm_common_xlabel(). Optional argument. Users can also supply character string here instead.

ylabel

ylabel layer that will determine the label of the combined plot's y-axis. This is created using sm_common_ylabel(). Optional argument. Users can also supply character string here instead.

legend

ggplot() layer that has legend. Optional argument.

ncol

Number of columns in the combined plot

nrow

Number of rows in the combined plot

xlabel2

2nd xlabel layer that will determine the label of the combined plot's secondary x-axis. This is created using sm_common_xlabel(). Optional argument. Users can also supply character string here instead.

ylabel2

2nd ylabel layer that will determine the label of the combined plot's y-axis. This is created using sm_common_ylabel(). Optional argument. Users can also supply character string here instead.

tickRatio

Relative size of the ticks to the default aesthetics of the thematic functions (ex. sm_hgrid()). By default, it adjusts tickRatio based on the given plot. But this can be overwritten if the input is supplied (ex. try 1.4 to begin with). FOr example, 1.4x means that it is 1.4x larger than the tick size of a single given plot.

panel_scale

Scale of the panel. Default is set to 0.9 to reduce empty space within and around each panel. The user can set to a value from 0 to 1 to see what happens to the spacing within each panel and between panels.

wRatio

This adjusts the ratio of the width of the first column to those of other columns. By default, it adjusts wRatio based on the given plot. However, this can be overwritten if the input is supplied. If the value is larger than 1, then it will be wider than that of other columns. Users are encouraged to adjust this value because different computers can show different looking outputs.

hRatio

This adjusts the ratio of the height of the last row to those of other rows By default, it adjusts hRatio based on the given plot. However, this can be overwritten if the input is supplied. If the value is larger than 1, then it will be taller than that of other columns. Users are encouraged to adjust this value because different computers can show different looking outputs.

hmargin

The amount of height of blank space between subplots. It sets the size of the empty space (i.e., margin) between panels. T he default is set to 0. If its positive, the blank spacing will increase. If its negative, it will get reduced between panels.

wmargin

The amount of width of blank space between subplots. It sets the size of the empty space (i.e., margin) between panels. T he default is set to 0. If its positive, the blank spacing will increase. If its negative, it will get reduced between panels.

remove_ticks

If set to 'some', x-axis ticks and y-axis ticks will be removed in inner plots. If set to 'all', then all panels' ticks will be removed. If set to 'none', then all panels' ticks will be kept.

wRatio2

This adjusts the ratio of the width of the last column to those of other columns. By default, it adjusts wRatio2 based on the given plot. However, this can be overwritten if the input is supplied. If the value is larger than 1, then it will be wider than that of other columns. Users are encouraged to adjust this value because different computers can show different looking outputs.

hRatio2

This adjusts the ratio of the height of the first row to those of other rows By default, it adjusts hRatio2 based on the given plot. However, this can be overwritten if the input is supplied. If the value is larger than 1, then it will be taller than that of other columns. Users are encouraged to adjust this value because different computers can show different looking outputs.

labelRatio

Relative text size of the labels, such as title, xlabel, ylabel, xlabel2 and ylabel2 to its default font size (optimized). This input only changes the size if the inputs are provided as character strings. The default value is 1. If this input is larger than 1.1, then the text size will be larger 1.1x than the default size, which itself is optimized based on the plot's given layout and other information.

Details

The inputs for the axis labels can be created with sm_common_xlabel(), sm_common_ylabel() and sm_common_title(). Alternatively, users can supply character strings directly to sm_put_together() instead. However, this option is not flexible but the function tries its best to find the optimal size and location given the plot information.

Value

Returns a combined figure.

Examples

library(smplot2)
library(ggplot2)

ggplot(data = mtcars, mapping = aes(x = drat, y = mpg)) +
geom_point(shape = 21, fill = '#0f993d', color = 'white',
          size = 3) -> p1

ggplot(data = mtcars, mapping = aes(x = drat, y = mpg)) +
  geom_point(shape = 21, fill = '#0f993d', color = 'white', size = 3) +
  sm_hvgrid() -> p2

title <- sm_common_title('My title')
xlabel <- sm_common_xlabel('My x-axis')
ylabel <- sm_common_ylabel('My y-axis')

sm_put_together(list(p1,p2), title=title, xlabel=xlabel,
                ylabel=ylabel, ncol=2,nrow=1)

sm_put_together(list(p1,p2), title='My title', xlabel='My x-axis',
                ylabel='My y-axis', labelRatio = 1.1, ncol=2,nrow=1)


smin95/sesplot documentation built on July 2, 2024, 9:35 a.m.