Y. Z.
Y. Z.

Reputation: 377

Add inline .svg image in Rmarkdown

I have used ![](https://image.png){width=25px} for inline image but it seems not working with .svg image.

Is there any way that I can use this image in my rmarkdown?

Upvotes: 1

Views: 1110

Answers (1)

Salim B
Salim B

Reputation: 2719

You could use the R package rsvg to convert the SVG to PDF

rsvg::rsvg_pdf(svg = "https://upload.wikimedia.org/wikipedia/commons/1/15/Florida_in_United_States.svg",
               file = "image.pdf")

and then include that PDF as you're used to

![](image.pdf){width=25px}

You could also convert the SVG to another image format supported by knitr using the other rsvg::rsvg_* converter functions, e.g. to PNG via rsvg::rsvg_png(). But I'd recommend to stick with vector image formats like PDF or EPS since they will print in crisp sharpness.

Note that if you install rsvg from source (likely the case on Linux), additional system dependencies are required.

Upvotes: 2

Related Questions