Movatterモバイル変換


[0]ホーム

URL:


Skip to contents

Save plots to file

Source:R/plot.R
save_plot.Rd

This function takes a plot or list of plots and writes them to a (multipage) file.

Usage

save_plot(  plot=ggplot2::last_plot(),filename,  width=NA,  height=NA,  units=c("mm","cm","in"),  padding=0.1,  multiple_files=FALSE,  view_plot=TRUE,...)

Arguments

plot

Plot to save, defaults to last plot displayed.

filename

File name to create on disk.

width, height

Dimensions of the graphic device to save the plot.Defaults toNA. In case ofNA, the dimensions are inferred from theincomingplot object (see Details).

units

Units of length. Defaults to"mm".

padding

Extra space around the saved plot. Defaults to0.1 meaning 10%.

multiple_files

Whether to save multiple pages as individual files.

view_plot

Whether to view the plot on screen after saving.

...

Other arguments passed on to the graphics device function,as specified bydevice.

Value

Atidyplot object.

Details

Handling of file dimensions.Output file dimensions are determined according the the following precedence.

  1. Thewidth andheight arguments.

  2. Dimensions inferred from the incomingplot object with absolute dimensions.

  3. System default device dimensions.

Examples

# Save plot to filestudy|>tidyplot(treatment,score)|>add_data_points()|>save_plot("single_plot.pdf")#> save_plot: saved tosingle_plot.pdf# Save intermediate stages to filestudy|>tidyplot(x=treatment, y=score, color=treatment)|>add_mean_bar(alpha=0.4)|>add_sem_errorbar()|>add_data_points_beeswarm()|>save_plot("before.pdf")|>adjust_colors(colors_discrete_seaside)|>save_plot("after.pdf")#> save_plot: saved tobefore.pdf#> save_plot: saved toafter.pdf# \donttest{# Save multipage PDF filegene_expression|>dplyr::slice_head(n=160)|>tidyplot(group,expression, color=sample_type)|>add_data_points()|>adjust_size(width=30, height=25)|>split_plot(by=external_gene_name, nrow=2, ncol=2)|>save_plot("multipage_plot.pdf")#> split_plot: split into8 plots across2 pages#> save_plot: saved multipage PDF tomultipage_plot.pdf#> [[1]]#>#> [[2]]#># Save multiple PDF filesgene_expression|>dplyr::slice_head(n=160)|>tidyplot(group,expression, color=sample_type)|>add_data_points()|>adjust_size(width=30, height=25)|>split_plot(by=external_gene_name, nrow=2, ncol=2)|>save_plot("plot.pdf", multiple_files=TRUE)#> split_plot: split into8 plots across2 pages#> save_plot: saved multiple plots toplot_1.pdf andplot_2.pdf#> [[1]]#>#> [[2]]#># }

[8]ページ先頭

©2009-2025 Movatter.jp