yihui/knitr — Issue #158: Using cached variables with ggplot2
Author: syoh
Created: 2012-03-01 07:27:00+00:00
State: open

Here is a minimal example

It seems that cached variables are not accessible by ggplot.
Please look at the "color" arguments using various "colvec" variables.

```latex
\documentclass{article}

\usepackage[margin=0.75in]{geometry}

\begin{document}

<>=
require(ggplot2)
x <- seq(0,2*pi,by=0.05)
df <- data.frame(a=x, b=sin(x))
colvec1 <- cos(x)
@

\newpage
Always Works!!
<>=
ggplot(df,aes(a,b,color=b)) + geom_line()
@

\newpage
Works! (plot cached, colvec1 not cached)
<>=
ggplot(df,aes(a,b,color=colvec1)) + geom_line()
@

\newpage
Does not work!
<>=
colvec2 <- -cos(x)
ggplot(df,aes(a,b,color=colvec2)) + geom_line()
@

\newpage
Works! (no cache)
<>=
colvec3 <- -cos(x)
ggplot(df,aes(a,b,color=colvec3)) + geom_line()
@

\end{document}
```