View source: R/graphtikzcode.R
| graph2texfile | R Documentation |
Based on tikzDevice::tikz.
graph2texfile( texte, output = tempfile(fileext = ".tex"), modify = NULL, widthe = 7, heighte = 7, caption = NULL, label = NULL, addfigureenv = FALSE, sanitize = FALSE, standalone = FALSE, addtopreamble = NULL, ... )
texte |
file containing tikz code |
modify |
a function that takes a character string as a parameter and returns a character string |
widthe |
a numeric |
heighte |
a numeric |
caption |
a character string. |
label |
a character string. |
addfigureenv |
a boolean |
sanitize |
a booleaan |
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 |
## First example: we generate the tikz code for a graph.
outputtexfile<-tempfile(fileext = ".tex")
graph2texfile(
"print(ggplot2::ggplot(data=cars,ggplot2::aes(x=speed,y=dist))+
ggplot2::geom_point())",
output=outputtexfile)
readLines(outputtexfile)
graph2texfile(
"print(ggplot2::ggplot(data=cars,ggplot2::aes(x=speed,y=dist))+
ggplot2::geom_point())",
standalone=TRUE,
output=outputtexfile,
modify=function(y){
gsub("dist","$\\\\\\\\left(1-\\\\\\\\exp\\\\\\\\left(-\\\\\\\\mathrm(x)^2\\\\\\\\right)\left(\\\\\\\\sin(\\\\\\\\mathrm{x})+\\\\\\\\mathds{1}_{\\\\\\\\{0\\\\\\\\}}(\\\\\\\\mathrm{x})\\\\\\\\right)$",y)})
readLines(outputtexfile)
system(paste0("cd ",dirname(outputtexfile),"; lualatex '",basename(outputtexfile),"';"))
fs::file_show(gsub(".tex",".pdf",outputtexfile))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.