Title: | Easily Save Output and Trace it Back to Code |
---|---|
Description: | Write output (plots and tables) ensuring traceability back to code. Includes a graphics saver with simple automation of stamping with source, destination and creation time. A list of plots can be saved at once. A user-friendly selection of output dimensions for presentations, on-screen inspections, and more available. |
Authors: | Philip Delff [aut, cre] |
Maintainer: | Philip Delff <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.4.901 |
Built: | 2024-11-26 06:08:43 UTC |
Source: | https://github.com/philipdelff/tracee |
Get predefined canvas sizes
canvasSize(canvas, scale = 1, simplify = TRUE)
canvasSize(canvas, scale = 1, simplify = TRUE)
canvas |
Can either be a character with one of the values
or it can be a list with elements width and height with single values (unit is inches). Example: canvas=list(height=5,width=9). |
scale |
A scale to apply to both directions of the canvas size. This can be useful in combination with the pre-defined canvas sizes. |
simplify |
If only one canvas returned and simplify=TRUE, the result will not be wrapped in a list. For programming, you most likely want simplify=FALSE to be sure to always get the same format back. |
A list with numerical elements width and height as used by ggwrite.
Other Plotting:
ggstamp()
,
ggwater()
,
ggwrite()
Stamp and write flextab objects to one or multiple formats
ftstamp(ft, file, script, bg = "#ffffff", time)
ftstamp(ft, file, script, bg = "#ffffff", time)
ft |
a flextable object |
file |
The file that the flextable will be written to (no file is written by this function) |
script |
path to script - will be pasted as caption. |
bg |
Default bacground colour is #ffffff. |
time |
The default is to insert a time stamp taken from result of Sys.time(). Using the time argument you can overrule this by setting a fixed string instead. Use "" to omit. |
Stamp and write flextab objects to one or multiple formats
ftwrite(ft, file, script, time, formats, save, quiet = FALSE, ...) writeFlextab(ft, file, script, formats, save, quiet = FALSE, ...)
ftwrite(ft, file, script, time, formats, save, quiet = FALSE, ...) writeFlextab(ft, file, script, formats, save, quiet = FALSE, ...)
ft |
A flextab object. |
file |
to save to. See formats to generate multiple files. |
script |
path to script - will be pasted as caption. If provided, a stamp will be included on the plot when writng file(s). |
time |
The default behavior is to include a time stamp if
|
formats |
One or more of png, docx, pptx, html. As a character vector. |
save |
Save the table to the given file or just show? Defaults to TRUE. Hint, if you use an "exportFlag", use save=exportFlag. |
quiet |
Default is false but use TRUE to suppress messages about what was saved. |
... |
Arguments passed to stampFlextab. |
writeFlextab()
: Deprecated function name. Use ftwrite.
This function is used to stamp ggplot type plots with datetime and script name. User must provide the script name.
ggstamp(plot, script = "", file, time = Sys.time())
ggstamp(plot, script = "", file, time = Sys.time())
plot |
The plot to be stamped. |
script |
the script name. Date and time will be added automatically. |
file |
An optional output filename to be included in the stamp. |
time |
The timestamp to be included. |
The stamp is adding using the caption label. If a caption is already in the plot, the stamp will be added in a new line.
The caption is derived as caption=paste(c(plot$label$caption,stamp,paste(date.txt,file)),collapse="\n")
ggplot 2.2.1 (which is years old) or newer is required.
the plot with a stamp
A plot object with the stamp added as caption
Other Plotting:
canvasSize()
,
ggwater()
,
ggwrite()
library(ggplot2) data(ChickWeight) p1 <- ggplot(ChickWeight,aes(Time,weight,group=Chick,colour=factor(Diet)))+geom_line() script <- "note" ggstamp(p1,script) ## Or use ggwrite which will call ggstamp when the `script` argument is provided. ggwrite(p1,script=script,canvas="wide")
library(ggplot2) data(ChickWeight) p1 <- ggplot(ChickWeight,aes(Time,weight,group=Chick,colour=factor(Diet)))+geom_line() script <- "note" ggstamp(p1,script) ## Or use ggwrite which will call ggstamp when the `script` argument is provided. ggwrite(p1,script=script,canvas="wide")
Add watermarks to ggplots
ggwater(text = "Not validated", scale = 1, rot = 30, col = "grey", alpha = 0.5)
ggwater(text = "Not validated", scale = 1, rot = 30, col = "grey", alpha = 0.5)
text |
What should be written on the plot |
scale |
the size |
rot |
rotation of the mark. Don't remember the unit. |
col |
the colour (a value, not an expression) of the watermark. Default is grey. |
alpha |
alpha value for the watermark. Default is 0.5. |
This used to be based on https://www.r-bloggers.com/adding-watermarks-to-plots/ That solution stopped working, and this new solution is simpler and based on ggplot2 alone.
a layer with a watermark that can be added to a plot
Other Plotting:
canvasSize()
,
ggstamp()
,
ggwrite()
library(ggplot2) ff <- qplot(1:10, 11:20) + ggwater()
library(ggplot2) ff <- qplot(1:10, 11:20) + ggwater()
Export plots created with ggplot (and more) or tables to files (png or pdf) - or show them on screen.
ggwrite( plot, file, script, time, canvas = "standard", formats, onefile = FALSE, res = 200, paper = "special", save = TRUE, show = !save, useNames = FALSE, quiet = FALSE )
ggwrite( plot, file, script, time, canvas = "standard", formats, onefile = FALSE, res = 200, paper = "special", save = TRUE, show = !save, useNames = FALSE, quiet = FALSE )
plot |
A plot object or a list of plots. Normally generated with ggplot or qplot. But it can also be from grid.arrange or arrangeGrob with class gtable. That is experimental though. Not sure exactly what classes are supported. |
file |
A file to export to. Must end in .png or .pdf. If plot is a list, see onefile. If missing, plot is shown on screen. |
script |
This should normally be the path to your script. Requires ggplot >=2.2.1. |
time |
Passed to ggwrite. |
canvas |
Either a list of height and width or a shortname of predefined canvas size. See ?canvasSize. |
formats |
File formats to write to as a character
vector. Must be a subset of c("png","pdf"). Default is to only
write to the format matching the file name extension of
|
onefile |
Only applicable if plot is a list. If plot is a list and onefile=TRUE, all plots will be put in a pdf (file must end in pdf) with one plot per page. If plot is a list and onefile=FALSE, numbered files will be created - one per list element. |
res |
Resolution. Passed to png. |
paper |
Only used with pdf device. See ?pdf. |
save |
Save the plot to the given file or just show? Defaults
to TRUE. If a variable is used to control whether a script
generates outputs (say |
show |
Print the plot to the screen? Defaults to the opposite of save. Hint, combining save and show in knitr can give you both a high quality plot in your pdf and a png optimized for powerpoint. |
useNames |
If length(plot)>1 use names(plot) in the file names? Default is to use 1:length(plot). Only used if save is TRUE, and length(plot)>1. |
quiet |
Default is false but use TRUE to suppress messages about what was saved. |
Nothing. Files written and/or plots shown, depending on argument values.
Other Plotting:
canvasSize()
,
ggstamp()
,
ggwater()
library(ggplot2) writeOutput <- FALSE data(ChickWeight) p1 <- ggplot(ChickWeight,aes(Time,weight,group=Chick,colour=factor(Diet)))+geom_line() ggwrite(p1) ## view plot on screen script <- "note" ggwrite(p1,script=script,canvas="wide",file="myplot1.png",save=writeOutput)
library(ggplot2) writeOutput <- FALSE data(ChickWeight) p1 <- ggplot(ChickWeight,aes(Time,weight,group=Chick,colour=factor(Diet)))+geom_line() ggwrite(p1) ## view plot on screen script <- "note" ggwrite(p1,script=script,canvas="wide",file="myplot1.png",save=writeOutput)
Stamp and write flextab objects to one or multiple formats
stampFlextab(ft, file, script, bg = "#ffffff", time)
stampFlextab(ft, file, script, bg = "#ffffff", time)
ft |
a flextable object |
file |
The file that the flextable will be written to (no file is written by this function) |
script |
path to script - will be pasted as caption. |
bg |
Default bacground colour is #ffffff. |
time |
The default is to insert a time stamp taken from result of Sys.time(). Using the time argument you can overrule this by setting a fixed string instead. Use "" to omit. |