View source: R/graphtikzcode.R
| graphtikzcode | R Documentation |
Based on tikzDevice::tikz.
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, ... )
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 |
## 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.