Learn R Programming

tikzDevice (version 0.5.0)

tikz: TikZ Graphics Device

Description

tikz is used to open a R graphics device which supports output in the TikZ graphics language. TikZ code may be included inside a LaTeX document by specifying \usepackage{tikz} in the document header.

Usage

tikz(file = "Rplots.tex", width = 7, height = 7,
	  bg="transparent", fg="black", pointsize = 10, standAlone = FALSE, 
	  bareBones = FALSE, console = FALSE, sanitize = FALSE,
	  documentDeclaration = getOption("tikzDocumentDeclaration"),
	  packages = getOption("tikzLatexPackages"),
	  footer = getOption("tikzFooter"))

Arguments

file
A character string indicating the desired path to the output file.
width
The width of the output figure, in inches.
height
The height of the output figure, in inches.
bg
The starting background color for the plot.
fg
The starting foreground color for the plot.
pointsize
Base pointsize used in the LaTeX document. This option is only used if a valid pointsize cannot be extracted from the value of getOption("tikzDocumentDeclaration"). See the section ``Font Size Calculations'' for more details.
standAlone
A logical value indicating whether the output file should be suitable for direct processing by LaTeX. A value of FALSE indicates that the file is intended for inclusion in a larger document. See Details.
bareBones
A logical value. When TRUE the figure will not be wrapped in a tikzpicture environment. This option is useful for embedding one TikZ picture within another. When TRUE multipage output will be drawn on a
console
Should the output of tikzDevice be directed to the R console (default FALSE). This is useful for dumping tikz output directly into a LaTeX document via sink. If TRUE, the file argumen
sanitize
Should special latex characters be replaced (Default FALSE). See the section ``Options That Affect Package Behavior'' for which characters are replaced.
documentDeclaration
See the sections ``Options That Affect Package Behavior'' and ``Font Size Calculations'' for more details.
packages
See the section ``Options That Affect Package Behavior.''
footer
See the section ``Options That Affect Package Behavior.''

Value

  • tikz() returns no values.

code

tikz

strong

LaTeX mathematics can be typeset directly into labels and annotations

preformatted

\documentclass[10pt]{article}

Font Size Calculations

The overarching goal of the tikzDevice is to provide seamless integration between text in R

itemize

  • The ``base font size'' specified when the graphics device is created.
  • The ``character expansion factor'' parameter, specified using thecexargument to functions such aspar.
  • The ``font size'' parameter, specified using thepsargument to functions such asparor thefontsizeargument to functions such asgpar.

Details

The TikZ device enables LaTeX-ready output from R

References

The TikZ and PGF Packages: Manual for version 2.00 http://sourceforge.net/projects/pgf Till Tantau, February 20, 2008

See Also

pictex, getLatexCharMetrics, getLatexStrWidth, setTikzDefaults, tikzAnnotate, sanitizeTexString

Examples

Run this code
## 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()

# View the output
tools::texi2dvi(tf,pdf=T)
system(paste(getOption('pdfviewer'),file.path(td,'example1.pdf')))
setwd(oldwd)
################################################
		
## Example 2 ###################################
#Set up temporary work directory
td <- tempdir()
tf <- file.path(td,'example2.tex')
oldwd <- getwd()
setwd(td)

#LaTeX math symbol names
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 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)
################################################

## Example 3 ###################################
#Set up temporary work directory
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=main)
    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)
################################################

Run the code above in your browser using DataLab