if (FALSE) {
## 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 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)
################################################
## 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='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)
################################################
}
Run the code above in your browser using DataLab