printAndSave: Function printAndSave

Description Usage Arguments Details Value Author(s) Examples

Description

printAndSave is a wrapper around ggsave. It prints a ggplot2 object to the console/knitr report and saves as a graphic file. It defaults to larger fonts for the graphic file (more suitable for PPT). Graphic filetype is taken from the given filename and can be one of (png, bmp, tiff, jpg, pdf, svg).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
printAndSave(
  plotObject,
  filename,
  width = 7,
  height = 5,
  units = "in",
  res = 300,
  scale = 1,
  printFontSize = 12,
  saveFontSize = 24,
  scaleLegend = TRUE,
  printPlot = TRUE,
  savePlot = TRUE
)

Arguments

plotObject

A ggplot2 plotobject

filename

A path/filename for the graphic

width

Graphic width in inches (default = 7)

height

Graphic height in inches (default = 5)

units

Units for height and width ("in"|"cm"|"mm") (Default = "in")

res

Resolution in ppi (default=300)

scale

Multiplicative scaling factor (Default = 1)

printFontSize

Base font size for the graphic on the console/knitr (default=12)

saveFontSize

Base font size for the graphic file (default=24)

scaleLegend

Scale the legend smaller if font > 14 (Default = TRUE)

printPlot

Print to console if TRUE (Default=TRUE)

savePlot

Print to file if TRUE (Default = TRUE)

Details

I found I didn't like the default Legend sizes. I inserted code to increase the size of the print/knitr legend and decrease the size of the legend in the saved graphic file. This works well for images of about 5-7 inches but may not scale well to other image sizes. Set scaleLegend to FALSE to get the default behavior back or use legend.key.size in a theme to tweak to your own specifications.

Value

The print object

Author(s)

John Thompson, jrt@thompsonclan.org

Examples

1
2
3
printAndSave (Myggplot, "myfile.png") #all defaults
printAndSave (Myggplot, "myfile.png", width=5, height=4, res=150, printFontSize=10,
               saveFontSize=18)  #set a few options

jrthompson54/DGE.Tools2 documentation built on May 12, 2021, 8:47 p.m.