graphtikzcode: Reads the output file of the tikz command into an R character...

View source: R/graphtikzcode.R

graphtikzcodeR Documentation

Reads the output file of the tikz command into an R character string.

Description

Based on tikzDevice::tikz.

Usage

graphtikzcode(
  texte,
  widthe = 7,
  heighte = 7,
  scale = c(1, 1),
  yxratio = c(1, 1),
  caption = NULL,
  label = NULL,
  addfigureenv = FALSE,
  sanitize = FALSE,
  modify = NULL,
  addtopreamble = character(0),
  standalone = FALSE,
  ...
)

Arguments

texte

file containing tikz code

widthe

a numeric

heighte

a numeric

caption

a character string.

label

a character string.

addfigureenv

a boolean

sanitize

a booleaan

modify

a function that takes a character string as a parameter and returns a character string

standalone

a booleaan

...

additional parameters to pass to tikzDevice::tikz

scale=c(1, 1)

a two parameters scale to apply to the graph

yxratio=c(1, 1),
usepackages

a character string

Examples

## First example: we generate the tikz code for a graph.
library(ggplot2)
texte="print(ggplot(data=cars,aes(x=speed,y=dist))+geom_point())"
graphtikzcode("print(ggplot(data=cars,aes(x=speed,y=dist))+geom_point())")
## Second example, we create a rnw file 
## This rnw file will be interpretated by Sweave and will print the 
## tikz dode of the plot into the corresponding tex file. 

figonlyrnwfile<-tempfile(fileext = ".rnw")
file.create(figonlyrnwfile);
sink(figonlyrnwfile)
cat(
'\\Sexpr{graphtikzcode("print(ggplot(data=cars,aes(x=speed,y=dist))+geom_point())")}
')
sink()
SweaveLst::Sweavelst(fullpath = figonlyrnwfile)
readLines(gsub(".rnw",".tex",figonlyrnwfile))

library(ggplot2)
figureX<-function(){
figureXX<-ggplot(data=cars,aes(x=speed,y=dist))+geom_point()
x=graphtikzcode("print(figureXX)")
graph2texfile("print(figureXX)",file.path(tempdir(),"figureX.tex"))
graph2pdffile("print(figureXX)",file.path(tempdir(),"figureX.pdf"))
}
figureX()
fs::file_show(file.path(tempdir(),"figureX.pdf"))

DanielBonnery/SweaveLst documentation built on May 4, 2022, 11:45 p.m.