Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize images in Xaringan presentation?

I'm trying to switch from ioslide to xaringan. I'm not able to properly resize a ggplot image to make full screen or al least to occupy as much space as possible. I'm using both fig.height/width and out.height/width arguments but only one dimension change. There is a better way to resize an image? this is the setup:

---
title: ""
author: ""
institute: ""
date: "`r Sys.Date()`"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
      ratio: 16:9
---
#```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
knitr::opts_chunk$set(fig.retina=2)

library(Cairo)
library(cairoDevice)
library(tidyverse)
library(kableExtra)
#```

--- 

# Plot

#```{r echo=FALSE, out.height=450, out.width= 2000}
knitr::include_graphics("img/Rplot01.svg")
#```

And this is the result: enter image description here

I would like to expand the image as much as possible

like image 290
Filippo Gambarota Avatar asked Oct 27 '19 16:10

Filippo Gambarota


2 Answers

To set the size of an image

You can use a markdown tag such as:

![:scale 50%](image.jpg)

see this

As a Background Image:

In Xaringan you can add images like this:

---
class: inverse, center, middle
background-image: url(img/Rplot01.svg")
background-size: contain

Please check that the info within url is correct.

As a guide you can see this presentation (the link drives you to slide number 9 where is an image) generated using this code (see line 76)

like image 200
Orlando Sabogal Avatar answered Oct 23 '22 17:10

Orlando Sabogal


You could also use the html <img> tag to resize and position an image in a Xaringan presentation slide.

<img src="https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg"
     width="500px" height="500px"
     style="position:absolute; right:10px; top:130px;">

like image 2
andschar Avatar answered Oct 23 '22 17:10

andschar