### Install tikzDevice from RForge Source: https://github.com/daqana/tikzdevice/blob/master/docs/index.html Installs a development build of the tikzDevice package from RForge. This method requires installation from source. ```R install.packages( 'tikzDevice', repos = 'https://rforge.net', type = 'source' ) ``` -------------------------------- ### Install tikzDevice from GitHub Source: https://github.com/daqana/tikzdevice/blob/master/docs/index.html Installs the tikzDevice package directly from its GitHub repository using the devtools package. ```R devtools::install_github( 'daqana/tikzDevice' ) ``` -------------------------------- ### Install tikzDevice from Source (GitHub) Source: https://github.com/daqana/tikzdevice/blob/master/docs/index.html Clones the tikzDevice repository from GitHub and installs it locally using devtools. This is for bleeding-edge source code. ```bash git clone git://github.com/daqana/tikzDevice.git ``` ```R devtools::install() ``` -------------------------------- ### Install tikzDevice from CRAN Source: https://github.com/daqana/tikzdevice/blob/master/docs/index.html Installs the stable version of the tikzDevice package from the Comprehensive R Archive Network (CRAN). ```R install.packages( 'tikzDevice' ) ``` -------------------------------- ### TikZ Device Math Example Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikz.html Generates a plot displaying LaTeX math symbols using the TikZ device. Requires setting up a temporary directory and writing a .tex file. ```R td <- tempdir() tf <- file.path(td,'example2.tex') oldwd <- getwd() setwd(td) syms <- c('alpha','theta','tau','beta','vartheta','pi','upsilon', 'gamma','gamma','varpi','phi','delta','kappa','rho', 'varphi','epsilon','lambda','varrho','chi','varepsilon', 'mu','sigma','psi','zeta','nu','varsigma','omega','eta', 'xi','Gamma','Lambda','Sigma','Psi','Delta','Xi','Upsilon', 'Omega','Theta','Pi','Phi') x <- rnorm(length(syms)) y <- rnorm(length(syms)) tikz(tf,standAlone=TRUE) plot(-2:2, -2:2, type = "n", axes=F, xlab='',ylab='', main='TikZ Device Math Example') text(x,y,paste('\\Large$\\\\',syms,'$',sep='')) dev.off() #View the output tools::texi2dvi(tf,pdf=TRUE) system(paste(getOption('pdfviewer'),file.path(td,'example2.pdf'))) setwd(oldwd) ``` -------------------------------- ### TikZ Device Random Circles Example Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikz.html Generates a plot of random circles with varying colors and transparency using the TikZ device. Requires setting up a temporary directory and writing a .tex file. ```R td <- tempdir() tf <- file.path(td,'example3.tex') oldwd <- getwd() setwd(td) tikz(tf,standAlone=TRUE) plot(-2:2, -2:2, type = "n", axes=F, xlab='',ylab='', main='Random Circles') points(rnorm(50), rnorm(50), pch=21, bg=rainbow(50,alpha=.5), cex=10) dev.off() #View the output tools::texi2dvi(tf,pdf=TRUE) system(paste(getOption('pdfviewer'),file.path(td,'example3.pdf'))) setwd(oldwd) ``` -------------------------------- ### Basic TikZ Plotting Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikz.html Generates a minimal plot and saves it as a standalone LaTeX document. Requires a working LaTeX installation and PGF/TikZ package. ```R # NOT RUN { ## Example 1 ################################### #Set up temporary work directory td <- tempdir() tf <- file.path(td,'example1.tex') oldwd <- getwd() setwd(td) # Minimal plot tikz(tf,standAlone=TRUE) plot(1) dev.off() ``` -------------------------------- ### Get Character Metrics from LaTeX Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/getLatexStrWidth.html Retrieves the ascent, descent, and width for a specific character (identified by its ASCII code) using LaTeX rendering. This provides detailed font metric information for individual characters. ```R # Calculate ascent, descent and width for "A" getLatexCharMetrics(65) ``` -------------------------------- ### getLatexStrWidth() / getLatexCharMetrics() Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/index.html Obtain font metrics from LaTeX. This function is used to get information about font dimensions within a LaTeX environment. ```APIDOC ## getLatexStrWidth() / getLatexCharMetrics() ### Description Obtain Font Metrics from LaTeX. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Check for Multibyte UTF-8 Characters (FALSE) Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/anyMultibyteUTF8Characters.html Use this function to determine if a string contains multibyte UTF-8 characters. This example demonstrates a case where the function returns FALSE. ```R anyMultibyteUTF8Characters('R is GNU copyright but not restricted') ``` -------------------------------- ### Check for Multibyte UTF-8 Characters (TRUE) Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/anyMultibyteUTF8Characters.html Use this function to determine if a string contains multibyte UTF-8 characters. This example demonstrates a case where the function returns TRUE. ```R anyMultibyteUTF8Characters('R is GNU ©, but not ®') ``` -------------------------------- ### grid.tikzAnnotate Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html High-level wrapper function to create and render a tikzAnnotate grob in one step within Grid graphics. ```APIDOC ## grid.tikzAnnotate ### Description Creates and renders a `tikzAnnotateGrob` in one step within Grid graphics. ### Function Signature grid.tikzAnnotate(annotation, draw = TRUE) ### Parameters #### Arguments - **annotation** (character vector) - A character vector, one element per line to be added to the open tikz device. - **draw** (logical) - A logical value indicating whether graphics output should be produced. ### Value Nothing returned. ``` -------------------------------- ### tikzDevice-package Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/index.html Support for native LaTeX output of R graphics. This is the main package documentation entry. ```APIDOC ## tikzDevice-package ### Description Support for native LaTeX output of R graphics. ### Method N/A (R package) ### Endpoint N/A (R package) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### tikzAnnotate() / tikzNode() / tikzCoord() / tikzAnnotateGrob() / tikzNodeGrob() / tikzCoordGrob() / grid.tikzAnnotate() / grid.tikzNode() / grid.tikzCoord() Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/index.html Add custom TikZ code to an active device. This set of functions allows for the integration of custom TikZ elements into plots. ```APIDOC ## tikzAnnotate() / tikzNode() / tikzCoord() / tikzAnnotateGrob() / tikzNodeGrob() / tikzCoordGrob() / grid.tikzAnnotate() / grid.tikzNode() / grid.tikzCoord() ### Description Add Custom TikZ Code to an Active Device. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### grid.tikzCoord Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html High-level wrapper function to create and render a tikzCoord grob in one step within Grid graphics. ```APIDOC ## grid.tikzCoord ### Description Creates and renders a `tikzCoordGrob` in one step within Grid graphics. ### Function Signature grid.tikzCoord(x, y, name, units = "native", draw = TRUE) ### Parameters #### Arguments - **x** (numeric) - x location for a named coordinate in user coordinates. - **y** (numeric) - y location for a named coordinate in user coordinates. - **name** (character string) - Name for the coordinate. - **units** (character string) - Unit system for `x` and `y`. Defaults to "native" for grid graphics. - **draw** (logical) - A logical value indicating whether graphics output should be produced. ### Value Nothing returned. ``` -------------------------------- ### Demonstrate and Reset tikzDocumentDeclaration Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/setTikzDefaults.html Shows the current value of 'tikzDocumentDeclaration', sets it to 'foo', then resets it using setTikzDefaults() to show it reverts to the default. ```R print(options('tikzDocumentDeclaration')) options(tikzDocumentDeclaration = 'foo') setTikzDefaults() print(options('tikzDocumentDeclaration')) ``` -------------------------------- ### grid.tikzNode Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html High-level wrapper function to create and render a tikzNode grob in one step within Grid graphics. ```APIDOC ## grid.tikzNode ### Description Creates and renders a `tikzNodeGrob` in one step within Grid graphics. ### Function Signature grid.tikzNode(x = NULL, y = NULL, opts = NULL, name = NULL, content = NULL, units = "native", draw = TRUE) ### Parameters #### Arguments - **x** (numeric) - x location for a named coordinate in user coordinates. - **y** (numeric) - y location for a named coordinate in user coordinates. - **opts** (character string) - Options for a `node`. - **name** (character string, optional) - Name for a `coordinate` or `node`. - **content** (character string) - Content to be displayed inside a `node`. If `NULL`, a `coordinate` is created. If an empty string `""` is passed, an empty node is created. - **units** (character string) - Unit system for `x` and `y`. Defaults to "native" for grid graphics. - **draw** (logical) - A logical value indicating whether graphics output should be produced. ### Value Nothing returned. ``` -------------------------------- ### tikzCompilerInfo() Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/index.html Print paths to TeX compilers. This utility function helps in debugging by showing the locations of the TeX compilers used by tikzDevice. ```APIDOC ## tikzCompilerInfo() ### Description Print paths to TeX compilers. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### gridToDevice Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/gridToDevice.html Converts a coordinate pair specifying a location in a grid viewport() in grid units to a coordinate pair specifying a location in device units relative to the lower left corner of the plotting canvas. ```APIDOC ## gridToDevice ### Description Converts a coordinate pair specifying a location in a grid `viewport()` in grid units to a coordinate pair specifying a location in device units relative to the lower left corner of the plotting canvas. ### Function Signature gridToDevice(x = 0, y = 0, units = "native") ### Arguments * **x** (numeric) - x coordinate. * **y** (numeric) - y coordinate. If no values are given for `x` and `y`, the location of the lower-left corner of the current viewport will be calculated. * **units** (character) - Character string indicating the units of `x` and `y`. See the `unit()` function for acceptable unit types. ### Value A tuple of coordinates in device units. ### See Also `unit()`, `viewport()`, `convertX()`, `convertY()`, `current.transform()` ``` -------------------------------- ### Set tikzMetricsDictionary Option Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzDevice-package.html Specifies a permanent cache file location for LaTeX font metrics. This can improve performance by caching computation results. ```R options(tikzMetricsDictionary = '/path/to/dictionary/location') ``` -------------------------------- ### Set tikzLatex Option Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzDevice-package.html Specifies the location of the LaTeX compiler. Useful for helping the package locate a missing compiler. ```R options(tikzLatex = '/path/to/latex/compiler') ``` -------------------------------- ### tikzNodeGrob Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html Creates a grid grob for inserting TikZ \node or \coordinates commands within Grid graphics. ```APIDOC ## tikzNodeGrob ### Description Creates a grid object or "grob" for inserting TikZ `\node` or `\coordinates` commands within Grid graphics. ### Function Signature tikzNodeGrob(x = NULL, y = NULL, opts = NULL, name = NULL, content = NULL, units = "native") ### Parameters #### Arguments - **x** (numeric) - x location for a named coordinate in user coordinates. - **y** (numeric) - y location for a named coordinate in user coordinates. - **opts** (character string) - Options for a `node`. - **name** (character string, optional) - Name for a `coordinate` or `node`. - **content** (character string) - Content to be displayed inside a `node`. If `NULL`, a `coordinate` is created. If an empty string `""` is passed, an empty node is created. - **units** (character string) - Unit system for `x` and `y`. Defaults to "native" for grid graphics. ### Value A grid graphical object (grob). ``` -------------------------------- ### tikzCoordGrob Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html Creates a grid grob for simplifying the insertion of named coordinates within Grid graphics. ```APIDOC ## tikzCoordGrob ### Description Creates a grid object or "grob" that simplifies the task of inserting named coordinates within Grid graphics. ### Function Signature tikzCoordGrob(x, y, name, units = "native") ### Parameters #### Arguments - **x** (numeric) - x location for a named coordinate in user coordinates. - **y** (numeric) - y location for a named coordinate in user coordinates. - **name** (character string) - Name for the coordinate. - **units** (character string) - Unit system for `x` and `y`. Defaults to "native" for grid graphics. ### Value A grid graphical object (grob). ``` -------------------------------- ### Reset tikzDevice Defaults Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/setTikzDefaults.html Resets all tikzDevice options to their default values. Use this to ensure a clean state. ```R setTikzDefaults(overwrite = TRUE) ``` -------------------------------- ### setTikzDefaults() Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/index.html Reset tikzDevice options to default values. This function allows users to revert the device settings to their initial state. ```APIDOC ## setTikzDefaults() ### Description Reset tikzDevice options to default values. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### tikzNode Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html A wrapper for tikzAnnotate that inserts TikZ \node or \coordinates commands into the output. It can create nodes with content or named coordinates. ```APIDOC ## tikzNode ### Description Inserts TikZ `\node` or `\coordinates` commands into the output. The difference between a node and a coordinate is the presence of a `content` section. ### Function Signature tikzNode(x = NULL, y = NULL, opts = NULL, name = NULL, content = NULL, units = "user") ### Parameters #### Arguments - **x** (numeric) - x location for a named coordinate in user coordinates. - **y** (numeric) - y location for a named coordinate in user coordinates. - **opts** (character string) - Options for a `node`. See the "Nodes and Edges" section of the TikZ manual. - **name** (character string, optional) - Name for a `coordinate` or `node`. Other TikZ commands can use this name to refer to a location. - **content** (character string) - Content to be displayed inside a `node`. If `NULL`, a `coordinate` is created. If an empty string `""` is passed, an empty node is created. - **units** (character string) - Unit system for `x` and `y`. See `grconvertX()` or `unit()` for acceptable units. ### Value Nothing returned. ``` -------------------------------- ### Calculate String Width with LaTeX Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/getLatexStrWidth.html Calculates the width of a given string, including LaTeX markup, as it would be rendered by LaTeX. This is useful for precise text placement in plots. ```R getLatexStrWidth('{\\\\tiny Hello \\\\LaTeX!}') ``` -------------------------------- ### tikz() Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/index.html TikZ Graphics Device. This is the primary function to create a TikZ graphics device for generating LaTeX output. ```APIDOC ## tikz() ### Description TikZ Graphics Device. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Open TikZ Graphics Device Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikz.html Opens a R graphics device that outputs in the TikZ graphics language. This is useful for generating plots that can be directly included in LaTeX documents using the \usepackage{tikz} command. ```R tikz( file = filename, filename = ifelse(onefile, "./Rplots.tex", "./Rplot%03d.tex"), width = 7, height = 7, onefile = TRUE, bg = "transparent", fg = "black", pointsize = 10, lwdUnit = getOption("tikzLwdUnit"), standAlone = FALSE, bareBones = FALSE, console = FALSE, sanitize = FALSE, engine = getOption("tikzDefaultEngine"), documentDeclaration = getOption("tikzDocumentDeclaration"), packages, footer = getOption("tikzFooter"), symbolicColors = getOption("tikzSymbolicColors"), colorFileName = "%s_colors.tex", maxSymbolicColors = getOption("tikzMaxSymbolicColors"), timestamp = TRUE, verbose = interactive() ) ``` -------------------------------- ### tikzTest() Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/index.html Test invocation of a LaTeX engine. This function is used to verify that the LaTeX engine can be successfully invoked by tikzDevice. ```APIDOC ## tikzTest() ### Description Test invocation of a LaTeX engine. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Print TeX Compiler Information Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzCompilerInfo.html Call tikzCompilerInfo with verbose set to TRUE to display paths to TeX compilers used by the tikz device. This function reports on LaTeX, XeLaTeX, and LuaLaTeX if found. ```R tikzCompilerInfo(verbose = TRUE) ``` -------------------------------- ### tikz() function Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikz.html Opens an R graphics device that supports output in the TikZ graphics language. This allows for the generation of TikZ code that can be included in LaTeX documents. ```APIDOC ## tikz() ### Description Opens an R graphics device for output in the TikZ graphics language. ### Function Signature tikz(file = filename, filename = ifelse(onefile, "./Rplots.tex", "./Rplot%03d.tex"), width = 7, height = 7, onefile = TRUE, bg = "transparent", fg = "black", pointsize = 10, lwdUnit = getOption("tikzLwdUnit"), standAlone = FALSE, bareBones = FALSE, console = FALSE, sanitize = FALSE, engine = getOption("tikzDefaultEngine"), documentDeclaration = getOption("tikzDocumentDeclaration"), packages, footer = getOption("tikzFooter"), symbolicColors = getOption("tikzSymbolicColors"), colorFileName = "%s_colors.tex", maxSymbolicColors = getOption("tikzMaxSymbolicColors"), timestamp = TRUE, verbose = interactive()) ### Arguments #### File Output - **file** (character string) - Desired path to the output file. Preferred over `filename` if both are used. - **filename** (character string) - Default path for output files. Uses a pattern for multiple files if `onefile` is FALSE. #### Dimensions - **width** (numeric) - The width of the output figure in inches. - **height** (numeric) - The height of the output figure in inches. #### Output Control - **onefile** (logical) - If TRUE, output is directed to separate environments in a single file. If FALSE, behaves like `pdf()`'s `onefile` argument. - **bg** (character string) - The starting background color for the plot. - **fg** (character string) - The starting foreground color for the plot. - **pointsize** (numeric) - Base pointsize used in the LaTeX document. Used if `tikzDocumentDeclaration` option doesn't provide one. - **lwdUnit** (numeric) - The number of `pt`s in LaTeX that `lwd = 1` in R is translated to. - **standAlone** (logical) - If TRUE, the output file is suitable for direct LaTeX processing. If FALSE, it's intended for inclusion in a larger document. - **bareBones** (logical) - If TRUE, the figure is not wrapped in a `tikzpicture` environment. Useful for embedding TikZ pictures. Multipage output is drawn on a single page when TRUE. - **console** (logical) - If TRUE, output is directed to the R console. The `file` argument is ignored. Setting `file = ''` is equivalent. - **sanitize** (logical) - If TRUE, special LaTeX characters are replaced. Defaults to FALSE. - **engine** (string) - Specifies which TeX engine to use ('pdftex', 'xetex', 'luatex'). - **documentDeclaration** (string) - Controls document declaration for LaTeX. See package documentation for details. - **packages** (string) - Specifies LaTeX packages to be included. See package documentation for details. - **footer** (string) - Custom footer content for the output file. - **symbolicColors** (logical) - If TRUE, colors are written as symbolic names requiring definition in LaTeX. If FALSE, colors are written as RGB values. - **colorFileName** (string) - Filename pattern for symbolic color definitions. - **maxSymbolicColors** (numeric) - Maximum number of symbolic colors to define. - **timestamp** (logical) - If TRUE, includes a timestamp in the output. - **verbose** (logical) - If TRUE, provides verbose output during operation. ``` -------------------------------- ### Set tikzMetricPackages Option Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzDevice-package.html Specifies additional LaTeX packages to load for font metric calculations, ensuring compatibility between LaTeX and R character codes. ```R options(tikzMetricPackages = c( "\\usepackage[utf8]{inputenc}", "\\usepackage[T1]{fontenc}", "\\usetikzlibrary{calc}" )) ``` -------------------------------- ### tikzTest Function Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzTest.html Tests the invocation of a LaTeX engine by processing a given string. It can simulate dimension measurements and provides detailed error information. Users can specify the TeX engine, document declaration, and packages to be used. ```APIDOC ## tikzTest ### Description Tests the invocation of a LaTeX engine. This function simulates the measurement of dimensions and prints detailed information in case of errors. ### Function Signature tikzTest(texString = "A", engine = getOption("tikzDefaultEngine"), documentDeclaration = getOption("tikzDocumentDeclaration"), packages) ### Arguments #### texString - **texString** (string) - An arbitrary string for which the width is to be calculated. May contain LaTeX markup. #### engine - **engine** (string) - A string specifying which TeX engine to use. Possible values are 'pdftex', 'xetex' and 'luatex'. #### documentDeclaration - **documentDeclaration** (string) - Specifies the document declaration to be used for LaTeX processing. #### packages - **packages** (list or string) - Specifies the LaTeX packages to be included in the document preamble. ### See Also - `tikz()` ``` -------------------------------- ### getLatexStrWidth Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/getLatexStrWidth.html Calculates the width of a given string, potentially containing LaTeX markup, as it would appear after being compiled by LaTeX. It allows for customization of font size, face, TeX engine, and document settings. ```APIDOC ## getLatexStrWidth ### Description Calculates the width of a string, including LaTeX markup, as rendered by LaTeX. ### Arguments * **texString** (string) - The input string for which to calculate the width. Can include LaTeX markup. * **cex** (numeric) - A scaling factor for device output. Defaults to 1. * **face** (integer) - Specifies the font face (1:5). See `par` for details. * **engine** (string) - The TeX engine to use (e.g., 'pdftex', 'xetex', 'luatex'). Defaults to `getOption("tikzDefaultEngine")`. * **documentDeclaration** (string) - Document declaration settings. Defaults to `getOption("tikzDocumentDeclaration")`. * **packages** (any) - Additional packages to include. See `tikzDevice-package` documentation. * **verbose** (logical) - Whether to print diagnostic messages during measurement. Defaults to `TRUE` in interactive mode, `FALSE` otherwise. * **diagnose** (logical) - If `TRUE`, prints detailed error information. ### Value The width of `texString` in points. ``` -------------------------------- ### Set tikzDocumentDeclaration Option Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzDevice-package.html Sets the LaTeX documentclass declaration used for standalone output files and font metric calculations. ```R options(tikzDocumentDeclaration = "\\documentclass[10pt]{article}") ``` -------------------------------- ### tikzAnnotate Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html Allows arbitrary TikZ commands to be inserted into the output stream of an active tikzDevice. It can be used to add custom LaTeX commands to an R plot. ```APIDOC ## tikzAnnotate ### Description Allows custom (LaTeX) commands to be added to the output of an active tikzDevice. ### Function Signature tikzAnnotate(annotation, checkstate = TRUE) ### Parameters #### Arguments - **annotation** (character vector) - A character vector, one element per line to be added to the open tikz device. - **checkstate** (logical) - A logical, whether to "flush" the device state prior to writing the `annotation`. ### Value Nothing returned. ``` -------------------------------- ### tikzAnnotateGrob Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html Creates a grid graphical object (grob) for adding custom TikZ commands within Grid graphics. ```APIDOC ## tikzAnnotateGrob ### Description Creates a grid object or "grob" for adding custom TikZ commands within Grid graphics. ### Function Signature tikzAnnotateGrob(annotation) ### Parameters #### Arguments - **annotation** (character vector) - A character vector, one element per line to be added to the open tikz device. ### Value A grid graphical object (grob). ``` -------------------------------- ### tikzCoord Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html A wrapper for tikzNode that simplifies the task of inserting named coordinates into the TikZ output. ```APIDOC ## tikzCoord ### Description Simplifies the task of inserting named coordinates into the output stream of an active tikzDevice. ### Function Signature tikzCoord(x, y, name, units = "user") ### Parameters #### Arguments - **x** (numeric) - x location for a named coordinate in user coordinates. - **y** (numeric) - y location for a named coordinate in user coordinates. - **name** (character string) - Name for the coordinate. Other TikZ commands can use this name to refer to a location. - **units** (character string) - Unit system for `x` and `y`. See `grconvertX()` or `unit()` for acceptable units. ### Value Nothing returned. ``` -------------------------------- ### Annotating Grid Graphics with TikZ Nodes Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html Adds TikZ nodes with ellipse callout shapes to a grid graphics plot. Requires loading the grid package and TikZ libraries for shapes. ```R library(grid) tikz("grid_annotation.tex",width=4,height=4, packages = c(getOption('tikzLatexPackages'), "\\usetikzlibrary{shapes.callouts}") ) pushViewport(plotViewport()) pushViewport(dataViewport(1:10, 1:10)) grid.rect() grid.xaxis() grid.yaxis() grid.points(1:10, 1:10) for ( i in seq(2,8,2) ){ grid.tikzNode(i,i,opts='ellipse callout,draw,anchor=pointer',content=i) } dev.off() ``` -------------------------------- ### getLatexCharMetrics Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/getLatexStrWidth.html Retrieves font metrics (ascent, descent, and width) for a given character code, as rendered by LaTeX. This function is useful for precise character placement in graphics. ```APIDOC ## getLatexCharMetrics ### Description Retrieves font metrics (ascent, descent, and width) for a character code rendered by LaTeX. ### Arguments * **charCode** (integer) - An integer corresponding to a symbol in the ASCII character table under the Type 1 font encoding. * **cex** (numeric) - A scaling factor for device output. Defaults to 1. * **face** (integer) - Specifies the font face (1:5). See `par` for details. * **engine** (string) - The TeX engine to use (e.g., 'pdftex', 'xetex', 'luatex'). Defaults to `getOption("tikzDefaultEngine")`. * **documentDeclaration** (string) - Document declaration settings. Defaults to `getOption("tikzDocumentDeclaration")`. * **packages** (any) - Additional packages to include. See `tikzDevice-package` documentation. * **verbose** (logical) - Whether to print diagnostic messages during measurement. Defaults to `TRUE` in interactive mode, `FALSE` otherwise. ### Value A numeric vector containing ascent, descent, and width values. ``` -------------------------------- ### Annotating Base R Boxplot with TikZ Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/tikzAnnotate.html Adds a brace and a callout node to highlight outliers in a base R boxplot. Requires loading TikZ libraries for decorations and positioning. ```R # Load some additional TikZ libraries tikz("annotation.tex",width=4,height=4, packages = c(getOption('tikzLatexPackages'), "\\usetikzlibrary{decorations.pathreplacing}", "\\usetikzlibrary{positioning}", "\\usetikzlibrary{shapes.arrows,shapes.symbols}") ) p <- rgamma (300 ,1) outliers <- which( p > quantile(p,.75)+1.5*IQR(p) ) boxplot(p) # Add named coordinates that other TikZ commands can hook onto tikzCoord(1, min(p[outliers]), 'min outlier') tikzCoord(1, max(p[outliers]), 'max outlier') # Use tikzAnnotate to insert arbitrary code, such as drawing a # fancy path between min outlier and max outlier. tikzAnnotate(c("\\draw[very thick,red,", # Turn the path into a brace. 'decorate,decoration={brace,amplitude=12pt},', # Shift it 1em to the left of the coordinates 'transform canvas={xshift=-1em}]', '(min outlier) --', # Add a node with some text in the middle of the path 'node[single arrow,anchor=tip,fill=white,draw=green,', 'left=14pt,text width=0.70in,align=center]', '{Holy Outliers Batman!}', '(max outlier);')) # tikzNode can be used to place nodes with customized options and content tikzNode( opts='starburst,fill=green,draw=blue,very thick,right=of max outlier', content='Wow!' ) dev.off() ``` -------------------------------- ### sanitizeTexString() Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/index.html Replace LaTeX special characters in a string. This function ensures that strings intended for LaTeX are properly formatted. ```APIDOC ## sanitizeTexString() ### Description Replace LaTeX Special Characters in a String. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### sanitizeTexString Function Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/sanitizeTexString.html Replaces special LaTeX characters in a given string with specified replacement characters. This function is automatically called by tikzDevice when the `sanitize` option is set to TRUE. ```APIDOC ## sanitizeTexString ### Description Replaces special LaTeX characters in a string. This function is used by tikzDevice when `sanitize = TRUE` to replace special LaTeX characters. ### Function Signature sanitizeTexString(string, strip = getOption("tikzSanitizeCharacters"), replacement = getOption("tikzReplacementCharacters")) ### Arguments #### `string` - (character vector, length 1) - The input string to sanitize. #### `strip` - (character vector) - A character vector of single characters to search for and replace. #### `replacement` - (character vector) - A character vector of replacement values corresponding to the characters in `strip`. ### Value - (character vector, length 1) - The sanitized string with special characters replaced. ### Details This function iterates through the input string, replacing occurrences of characters found in `strip` with their corresponding values in `replacement`. The default characters to be stripped and their replacements are defined by `tikzSanitizeCharacters` and `tikzReplacementCharacters` options, which can be modified using `options()`. ### Examples ```R # Example of sanitizing a string with special LaTeX characters sanitizeTexString('10\% of 10$ is 10^\{-1\}$') ``` ### See Also - `[tikz()](tikz.html)` ``` -------------------------------- ### anyMultibyteUTF8Characters Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/anyMultibyteUTF8Characters.html Checks if a string contains multibyte UTF-8 characters. This function is used by tikzDevice to determine if string processing requires UTF-8 handling. ```APIDOC ## anyMultibyteUTF8Characters ### Description This function is used by tikzDevice to check if an incoming string contains multibyte UTF-8 characters. It searches through the characters in the given string; if any of the characters are more than one byte, the function returns `TRUE`, otherwise it returns `FALSE`. ### Details The function assumes an input encoding of UTF-8 but will take any specified encoding into account and will convert from the specified encoding to UTF-8 before doing any checks. ### Arguments * **string** (character vector of length 1) - The input string to check. * **encoding** (string) - Unused. Defaults to "UTF-8". ### Value * **boolean** - `TRUE` if the string contains multibyte UTF-8 characters, `FALSE` otherwise. ### Examples ```R # Example demonstrating TRUE anyMultibyteUTF8Characters('R is GNU ©, but not ®') # Expected output: TRUE # Example demonstrating FALSE anyMultibyteUTF8Characters('R is GNU copyright but not restricted') # Expected output: FALSE ``` ### See Also * `[tikz()](tikz.html)` ``` -------------------------------- ### Sanitize LaTeX Special Characters Source: https://github.com/daqana/tikzdevice/blob/master/docs/reference/sanitizeTexString.html Use sanitizeTexString to replace special LaTeX characters in a string. Be cautious as sanitization can sometimes lead to unexpected behavior, such as superscripts being removed. ```R sanitizeTexString('10\% of 10$ is 10^\{-1\}$') # } # NOT RUN ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.