forked from yihui/knitr-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
037-graphics-hyperlink.Rnw
38 lines (29 loc) · 1.12 KB
/
037-graphics-hyperlink.Rnw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
%% courtesy of Jonathan Kennel
%% library(knitr); knit('links.Rnw')
\documentclass{report}
\usepackage{tikz,hyperref}
\begin{document}
<<setup, include=FALSE>>=
## important to add \usepackage{hyperref} to metric packages!
options(tikzMetricPackages = c("\\usepackage[utf8]{inputenc}",
"\\usepackage[T1]{fontenc}", "\\usetikzlibrary{calc}", "\\usepackage{hyperref}"))
library(knitr)
opts_chunk$set(external = FALSE, cache = TRUE, fig.width = 5)
@
Create link texts in the data:
<<pltPreparation, tidy.opts=list(width.cutoff=50)>>=
library(lattice)
data(iris)
iris$hyperlink <- paste("\\hyperlink{",iris$Species,"}{",iris$Species,"}", sep = '')
iris$hypertarget <- paste("\\hypertarget{",iris$Species,"}{",iris$Species,"}", sep = '')
@
Draw these texts in plots (you can click on the labels):
<<pltFacet, dev = 'tikz'>>=
xyplot(Sepal.Length~Sepal.Width|hyperlink, data = iris)
@
<<pltInd, dev = 'tikz'>>=
xyplot(Sepal.Length~Sepal.Width|hypertarget, data = iris, layout= c(1,1))
@
Note the option external has to be FALSE here, otherwise LaTeX will not be able
to find the link target in the document.
\end{document}