Size of image in xaringan slides

xaringan

#1

I'm creating slides in RMarkdown using xaringan and I'd like to resize local images on my slides.

I have this line of code:

![](workshop-images/clustering.png){width=200px height=200px}

which doesn't change the size :frowning:

Does anyone know how to properly resize images in a xaringan slide?


#2

I prefer knitr::include_graphics for non-R plots. For rendered plots, I use my chunk options like fig.retina and out.width.

https://www.rforge.net/doc/packages/knitr/include_graphics.html


#3

@apreshill I'm actually making my slides by referring to your xaringan tutorial slides!

I've set out.width and out.height in the global options chunk and I used knitr::include_graphics
but I can't see my images in my slides, even though I can run the function in my Rmd

knitr::include_graphics("workshop-images/moon.jpg")

Do you know what the problem is?


#4

Hmm I don't - can you see the images fine with plain old markdown syntax? I typically do just one or the other of those 2 args, out.width on a per-plot-basis usually with fig.retina = 3 as a global. And I'm not sure what you mean re: run the function in your Rmd but can't see in your slides.


#5

Yes, I can see images fine with markdown syntax. But, I can't change the size of the image with markdown syntax, so I'm trying out knitr::include_graphics("workshop-images/moon.jpg")

Here is what I mean by "run the function in your Rmd but can't see in your slides.":

I can run the include_graphics function in my Rmd, but the image doesn't appear in my slides.


#6

OK- weird! A few follow-up questions then:

  1. Have you tried showing in a real browser window? Sometimes the RStudio viewer works not well. Click the icon next to the broom.
  2. If it is working on local render, I'm wondering whether you have a file path issue- is workshop-images a subfolder within the same directory that tryR-workshop-slides.Rmd is?
  3. You don't happen to have eval = FALSE set as a global chunk option in your .Rmd?
  4. Are you working in an R project?

If you want to share the repo I'll take a look!


#7
  1. Yep. A real browser window shows the same thing.
  2. Yes, workshop-images is a subfolder in the same directory that my Rmd file is.
  3. YES, I DO. I set eval = FALSE as a global chunk...
  4. Yes.

Here is my repo:

The code is in: tryR-workshop-slides.Rmd


#8

I fixed it!

Your #3 point was the reason why the image didn't render.

Also, using out.width and out.height in the global options chunk works too.

Thank you Alison.


#9

If your question's been answered, would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:


#10

Of course, Christophe

Solution: Change global chunk to eval = TRUE so that R can actually evaluate the code chunk:

knitr::include_graphics("workshop-images/moon.jpg")