Search code examples
rr-sfr-mapview

Align and size mapview window in Rmarkdown ioslides


I'm trying to both center and resize the interactive map window from mapview in an Rmarkdown ioslides presentation - so far no luck. A simple example:

---
title: "Untitled"
author: ""
date: ""
output: ioslides_presentation
---

## Slide 2 
```{r echo=F, message=F, warning=FALSE, fig.align='center'}
library(sf)
library(mapview)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
mapview(nc)
```

I'm guessing I need to apply a top-level css style customization to the document, but I'm not quite sure how to go about - any advice greatly appreciated.


Solution

  • To center add center tags above and below the code chunk. Then adjust size using the fig.width and fig.height arguments.

    ## Slide 2 
    <center>
    ```{r echo=F, message=F, warning=FALSE, fig.width=4}
    library(sf)
    library(mapview)
    nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
    mapview(nc)
    ```
    </center>
    

    enter image description here