Learn R Programming

tikzDevice (version 0.5.0)

tikzAnnotate: Annotate an active tikz device

Description

This function allows (LaTeX) commands to be added to an active tikzDevice.

Usage

tikzAnnotate( annotation ) 
	tikzCoord( x, y, name )

Arguments

annotation
A character vector, one element per line to be added to the open tikz device.
x
numeric, x location for a named coordinate in user coordinates
y
numeric, y location for a named coordinate in user coordinates
name
Character string giving a name for the coordinate (as seen by TikZ)

Value

  • Nothing returned.

Details

tikzAnnotate is intended to allow the drawing of TikZ commands for annotating graphics. If you annotate a graphic with a command that needs a coordinate you must convert user coordinates to device coordinates with the grconvertX or grconvertY function.

tikzCoord provides a way to reference a specific location in the graphic by name for annotation purposes.

See Also

grconvertX, grconvertY,tikzDevice, tikz

Examples

Run this code
#### 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