Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

r - Is it possible to include svg image in pdf document rendered by rmarkdown?

I want an svg image to be embedded in an pdf document that I render by using rmarkdown. This doesn't seem possible, or do I miss something? If it's not possible is there a way to first convert the .svg image to a .png before embedding it?

In my rmarkdown file it looks like this (notice the two different kinds of inserting the image):

```{r results="asis",eval=TRUE,echo=FALSE,message=FALSE, error=FALSE, warning=FALSE, comment = NA,fig.height=10}

cat("![](svg_file.svg)")

```

![](svg_file.svg)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Now we can simply use the cowplot library to read an image and plot it in R markdown.

```{r figSvg,eval=TRUE,echo=FALSE,message=FALSE, error=FALSE, warning=FALSE,fig.height=10}

library(cowplot)
fig_svg<-cowplot::ggdraw()+cowplot::draw_image("http://jeroen.github.io/images/tiger.svg")
plot(fig_svg)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...