3
我想使用在瀏覽器上將ggplot
對象顯示爲svg。在rmarkdown中顯示ggplot對象爲html svg代碼
---
title: ""
output: html_document
---
```{r setup, include = FALSE}
library(svglite)
library(ggplot2)
knitr::opts_chunk$set(
dev = "svglite",
fig.ext = ".svg"
)
```
```{r, warning = F}
data(cars)
ggplot(mtcars, aes(mpg, qsec, color = factor(cyl))) +
geom_point()
```
一切工作正常,但是當我在Chrome中打開它,並嘗試檢查元素事實證明,整個情節是內<img>
標籤。我想要實現的是創建 doc與整個ggplot
的html代碼。
我嘗試使用htmlSVG
函數,但它在ggplot
上不起作用。我得到一個錯誤:
Error in FUN(X[[i]], ...) : argumemt is not a character vector
但是,它工作得很好的基本情節 - htmlSVG(plot(data = sampled_df, z ~ price))
,當我包括它。
你知道可以用ggplot
對象做同樣的事嗎?