2

I'm trying to create a html with markdown. I want to include several plots using a for loop like this:

```{r plotofnas, echo=FALSE, fig.width=2, message=FALSE, warning=FALSE}
for (i in list) { 
  barplot(i)
  plot(i)
}

The problem is that I want different sizes for the first and the second plot in the loop, specifically, I want the barplot to have a smaller width than the other plot. Looking for a solution I came across the fig.width option, but this will change the size of all of my plots, not only the barplots. Is there a possibility to only change the size of specific plots in one block in markdown?

LNA
  • 71
  • 1
  • 5
  • 1
    Is https://stackoverflow.com/a/47339394/7162131 relevant? – henrik_ibsen Nov 18 '20 at 10:09
  • Thank you! The answer referring to http://michaeljw.com/blog/post/subchunkify/ provides a way how to do it. Unfortunately it doesn't work for me. The picture does not show. There is just one line like this included for every picture `## `. Probably just a small problem... but I don't know much about knitr. – LNA Nov 19 '20 at 14:04
  • Did you set `results='asis'` in the chunk options? – henrik_ibsen Nov 19 '20 at 14:28
  • Perfect! It works now. The only problem remaining is the text I want to put out in between different plots. I have several print statements to put out a bunch of variables and with asif everything is written in one line and hardly readable. Is there a possibiliy to avoid this? – LNA Nov 24 '20 at 15:20
  • You could try to remove `results='asis'` and use the function `knitr::asis_output()` only at the desired output. For example, place it only around the code that outputs ``. – henrik_ibsen Nov 25 '20 at 12:34

1 Answers1

0

In the chunk title, this might work:

{r out.width=c('500px','300px','500px'), fig.show='hold'}

This example is for 3 plots with the second having a smaller width than the first and third.

You could also do it with proportions if you wanted to shrink the entire image:

{r out.width=c('40%','20%','40%'), fig.show='hold'}

This answer was helpful: https://stackoverflow.com/a/14064253/12910533

missgwolf
  • 356
  • 1
  • 11