0

I'm trying to put an image generetad by mapview::mapshot into a rmarkdown pdf document :

---
title: "test"
output: pdf_document
date: '2023-01-03'
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(fig.pos = 'h')
library(knitr)
library(mapview)
```

## R Markdown

## Including Plots

You can also embed plots, for example:


```{r fig1x, fig.align ='center',echo=FALSE, message=FALSE, warning=FALSE,out.width = "500px", out.height="400px",fig.cap="My test location"}
library(leaflet)
df = data.frame(long=4,lat=55,Name="myLocation")

imgs = leaflet(option=leafletOptions(zoomControl=FALSE),width = "100%") %>%
      addProviderTiles("OpenTopoMap", group = "MapQuestOpen.Aerial") %>%
      setView(lat = df$lat, lng = df$long,zoom = 10)%>%
      addScaleBar(position = 'topright') %>%
      addCircles(data = df,~long, ~lat, radius = 20,label = ~as.character(Name))%>%
      addPopups(data=df,~long,~lat,  'My location')
mapshot(imgs, file ="map1.png")
include_graphics(paste0("map1.png"))

```

The image has lot of white space at the bottom so the caption is almost separated. Any idea how this can be fixed ?

Haribo
  • 2,071
  • 17
  • 37

0 Answers0