#### Example 1
library(tikzDevice)
options(tikzLatexPackages = c(getOption('tikzLatexPackages'),
"\\usetikzlibrary{shapes.arrows}"))
tikz(standAlone=TRUE)
plot(1)
x <- grconvertX(1,,'device')
y <- grconvertY(1,,'device')
tikzAnnotate(paste('\\node[single arrow,anchor=tip,draw,fill=green] at (',
x,',',y,') {Look over here!};'))
dev.off()
#### Example 2
options(tikzLatexPackages =
c(getOption('tikzLatexPackages'),
c("\\usetikzlibrary{decorations.pathreplacing}",
"\\usetikzlibrary{shapes.arrows}")))
p <- rgamma(300,1)
outliers <- which( p > quantile(p,.75)+1.5*IQR(p) )
tikz("annotation.tex",width=4,height=4)
boxplot(p)
min.outlier <- grconvertY(min( p[outliers] ),, "device")
max.outlier <- grconvertY(max( p[outliers] ),, "device")
x <- grconvertX(1,,"device")
tikzAnnotate(paste("\\node (min) at (",x,',',min.outlier,") {};"))
tikzAnnotate(paste("\\node (max) at (",x,',',max.outlier,") {};"))
tikzAnnotate(c("\\draw[decorate,very thick,red,",
"decoration={brace,amplitude=20pt}] (min) ",
"-- node[single arrow,anchor=tip,left=20pt,draw=green] ",
"{Look at These Outliers!} (max);"))
tikzAnnotate(c("\\node[starburst, fill=green, ",
"draw=blue, very thick,right=of max] (burst) {Wow!};"))
tikzAnnotate(c("\\draw[->, very thick] (burst.west) -- (max);"))
dev.off()
setTikzDefaults()
#### Example 3 - Using tikzCoord
tikz(standAlone=TRUE)
plot(1:2,type='l')
tikzCoord(1,1,'one')
tikzCoord(1,1,'two')
tikzAnnotate("\\draw[black] (one) -- (two);")
dev.off()
Run the code above in your browser using DataLab