graph2pngfile: Creates a png file by converting a graph to tikz and...

View source: R/graphtikzcode.R

graph2pngfileR Documentation

Creates a png file by converting a graph to tikz and lualatexing the output

Description

Based on tikzDevice::tikz.

Usage

graph2pngfile(
  texte,
  output = tempfile(fileext = ".png"),
  widthe = 7,
  heighte = 7,
  caption = NULL,
  label = NULL,
  addfigureenv = FALSE,
  sanitize = FALSE,
  modify = NULL,
  addtopreamble = NULL,
  texcompiler = "lualatex",
  ...
)

Arguments

texte

file containing tikz code

output

output fill path (will be overwritten if existing with no warning)

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

...

additional parameters to pass to tikzDevice::tikz

usepackages

a character string

Examples

## First example: we generate the tikz code for a graph. 

outputpngfile<-tempfile(fileext = ".png")
command="print(ggplot2::ggplot(data=cars,ggplot2::aes(x=speed,y=dist))+ggplot2::geom_point())"
graph2pngfile(command,output=outputpngfile)
readLines(outputpngfile)
fs::file_show(outputpngfile)
graph2pngfile(command,output=outputpngfile,widthe=7,heighte=3)
fs::file_show(outputpngfile)
command="print(ggplot2::ggplot(data=cars,ggplot2::aes(x=speed,y=dist,color=dist))+
ggplot2::geom_point())"
fs::file_show(graph2pngfile(command,widthe=7,heighte=3,modify=function(y){
gsub("dist","$\\frac{1-\\exp\\left(-\\mathrm(x)^2\\right)}{\\sin(\\mathrm{x})+\\mathds{1}_{\\{0\\}}(\\mathrm{x})}$",y)}))
convert a print (graph) expression to a png file.

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