0

I'm rendering a PDF with mapview. However, the output seems that it was too fast at getting a screenshot of the map and is not rendering it properly.

---
title: "test"
output:
  pdf_document: default
  html_document: default
date: "2024-04-27"
---

## Mapview rendering in markdown
```{r mapview, fig.width=2}
  library(mapview)
  library(sf)
  mapview(breweries)
```

enter image description here

As you can see in the PDF the scale is way too low and the legend is not in the plot. It also seems that the image is taking the whole space instead of the fig.width=2. The output of the map should look like this: enter image description here

1 Answer 1

0

Although I cannot reproduce your figure this might get you started.

Possibly the issue is with the use of fig.width=2 this means that the figure width will be 2 inches. See: https://bookdown.org/yihui/rmarkdown-cookbook/figure-size.html.

Adjusting for image size by controlling width (in inches) and aspect with fig.width and fig.asp, by trial and error.

You could also use fig.height to manage figure size.

The issues with 'scale' and 'legend in the plot' are resolved automatically.

I could not get rid of the grey left hand margin. Not sure where this is coming from, maybe a mapview argument could deal with this.

---
title: "mapview | breweries"
output: pdf_document
---

```{r mapview, fig.width=6.5, fig.asp=1.2}

  library(mapview)
  library(sf)

  mapview(breweries)
  
```

enter image description here

3
  • Interesting, when I do this it gives me an error. I can only set fig.asp=1. The error is Quitting from lines 11-14 [mapview] (test.Rmd) Error in s$close(): ! attempt to apply non-function [...]. Now I'm wondering if this is because I'm on macOS Sonoma. Commented Apr 27 at 21:10
  • I'm using a Windows set up so cannot comment on Macs. You could try using fig.height = 7 (or some other suitable value for image height ) and remove the fig.asp argument? I'm not familiar with the error message you describe.
    – Peter
    Commented Apr 28 at 5:13
  • Thanks! However, the frame is still taking the whole space... Commented Apr 28 at 23:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.