yihui/knitr — Issue #63: Rationalizing Plot Options
Author: ramnathv
Created: 2011-12-17 03:15:42+00:00
State: open

This is related to #59, but I am raising it separately as they concern rationalizing of plot options. To start with my focus is going to be on these five options related to plotting: `fig`, `fig.low`, `fig.hold`, `fig.last` and `fig.animate`. If you think about the scenarios controlled by these five options from an end-user perspective, you will realize that they answer two central questions.

1. What plots to keep for display? `fig`, `fig.low`. `fig.last`
2. How to arrange/show the plots? `fig.hold`, `animate`

Being an OR guy, I started thinking, do we really need so many options to account for all these scenarios? A closer scrutiny reveals that it would suffice to have just two options, which owing to lack of creativity on my part, I am going to call `fig.keep` and `fig.show`. Let me explain further.

## What plots to keep for display?

`fig.keep` decides which plots are kept for display. It can take four values

1. `none` produces no plots (same as `fig = F`)
2. `high` keeps only high level plots (same as `fig.low = F`)
3. `all` keeps all plots (same as `fig.low = T`)
4. `last` keeps only the last plot produced (same as `fig.last = T`)

Now, three boolean options generate a total of 8 scenarios. A simple truth table exercise (as shown below) will confirm that `fig.keep` covers all of them.

* When `fig = F`, none of the other options matter, implying that these 4 scenarios can all be represented by `fig.keep = none`.
* When `fig = T` and `fig.last = T`, `fig.low` does not matter since in any case only the last plot will be displayed. I know that it does not account for the case where low level plots are recorded, but only the last plot is displayed. But I can't think of too many use cases where it might be necessary. I am happy to be proved wrong. Hence, `fig.keep = last` cover these two scenarios .
* When `fig = T` and `fig.last = F`, `fig.low = T` is the same as `fig.keep = all` and `fig.low = F` is equivalent to `fig.keep = high`.

## How to arrange/show the plots?

`fig.show` controls how plots are shown in the output. It takes three values

1. `asis` shows plots inline as you would see at the R console (`fig.hold = F`)
2. `hold` shows plots at the end (`fig.hold = T`)
3. `animate` shows plots as an animation at the end (`animate = T`, `fig.hold = T`)

It eliminates one scenario where animations are displayed inline, right where the first plot is generated. But once again I find the use case for this limited. Glad to be proven wrong.

For now, this just remains an intellectual exercise, but just wanted to put it out there.