generate plots in loop to get markdown/html - possible bug

1,360 views
Skip to first unread message

Szilard

unread,
Jun 8, 2012, 8:39:56 PM6/8/12
to knitr
I'm trying to generate text-plot pairs with markdown and ultimately
html output:

```{r echo=FALSE}
library(ggplot2)
for(i in 1:3) {
cat(i)
plt <- qplot(x,y, data=data.frame(x=1:10,y=rnorm(10)) )
print(plt)
}
```

I'd like to get this:

1
plot1
2
plot2
...

Instead, I get this:

1
2
plot1
3
plot2
plot3

Is this a bug? Any work around? (I have lots of plots and the labels
would make it easy to "navigate" the html)

Yihui Xie

unread,
Jun 8, 2012, 10:17:31 PM6/8/12
to Szilard, knitr
I do not understand this either. Putting cat() after qplot() seems to work.

You may report this to Hadley, though
(https://github.com/hadley/evaluate/issues).

library(evaluate)
evaluate('library(ggplot2)
for(i in 1:3) {
cat(i)
plt <- qplot(x,y, data=data.frame(x=1:10,y=rnorm(10)) )
print(plt)
}')

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA

Szilard

unread,
Jun 8, 2012, 11:57:04 PM6/8/12
to knitr
OK, thanks.

Issue with evaluate reported here:
https://github.com/hadley/evaluate/issues/14


On Jun 8, 7:17 pm, Yihui Xie <xieyi...@gmail.com> wrote:
> I do not understand this either. Putting cat() after qplot() seems to work.
>
> You may report this to Hadley, though
> (https://github.com/hadley/evaluate/issues).
>
> library(evaluate)
> evaluate('library(ggplot2)
> for(i in 1:3) {
>    cat(i)
>    plt <- qplot(x,y, data=data.frame(x=1:10,y=rnorm(10)) )
>    print(plt)
>
> }')
>
> Regards,
> Yihui
> --
> Yihui Xie <xieyi...@gmail.com>
Reply all
Reply to author
Forward
0 new messages