if (FALSE) {
### Example 1: Annotations in Base Graphics
# Load some additional TikZ libraries
tikz("annotation.tex",width=4,height=4,
packages = c(getOption('tikzLatexPackages'),
"\\usetikzlibrary{decorations.pathreplacing}",
"\\usetikzlibrary{positioning}",
"\\usetikzlibrary{shapes.arrows,shapes.symbols}")
)
p <- rgamma (300 ,1)
outliers <- which( p > quantile(p,.75)+1.5*IQR(p) )
boxplot(p)
# Add named coordinates that other TikZ commands can hook onto
tikzCoord(1, min(p[outliers]), 'min outlier')
tikzCoord(1, max(p[outliers]), 'max outlier')
# Use tikzAnnotate to insert arbitrary code, such as drawing a
# fancy path between min outlier and max outlier.
tikzAnnotate(c("\\draw[very thick,red,",
# Turn the path into a brace.
'decorate,decoration={brace,amplitude=12pt},',
# Shift it 1em to the left of the coordinates
'transform canvas={xshift=-1em}]',
'(min outlier) --',
# Add a node with some text in the middle of the path
'node[single arrow,anchor=tip,fill=white,draw=green,',
'left=14pt,text width=0.70in,align=center]',
'{Holy Outliers Batman!}', '(max outlier);'))
# tikzNode can be used to place nodes with customized options and content
tikzNode(
opts='starburst,fill=green,draw=blue,very thick,right=of max outlier',
content='Wow!'
)
dev.off()
### Example 2: Annotations in Grid Graphics
library(grid)
tikz("grid_annotation.tex",width=4,height=4,
packages = c(getOption('tikzLatexPackages'),
"\\usetikzlibrary{shapes.callouts}")
)
pushViewport(plotViewport())
pushViewport(dataViewport(1:10, 1:10))
grid.rect()
grid.xaxis()
grid.yaxis()
grid.points(1:10, 1:10)
for ( i in seq(2,8,2) ){
grid.tikzNode(i,i,opts='ellipse callout,draw,anchor=pointer',content=i)
}
dev.off()
}
Run the code above in your browser using DataLab