- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道我是否可以在 .Rnw 中使用 ggvis 和 knitr。我在 RStudio Version 0.98.1091
中尝试了以下代码。但它不起作用。
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{geometry}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm}
\begin{document}
\chapter{Test}
\begin{figure}[H]
<< label = Plot1, fig.lp = "Plot1", fig.cap = "Test Plot" >>=
library(ggvis)
p <- mtcars %>% ggvis(x = ~wt, y = ~mpg) %>% layer_points()
print(p) # Commenting this line will compile the document
@
\end{figure}
\end{document}
它抛出以下错误:
LaTeX errors:
! Missing $ inserted.
<inserted text>
$
l.70 \end{kframe}<!--html_
preserve--><div id="plot_id298740869-container" cl...
! Please use \mathaccent for accents in math mode.
已编辑
注释 print(p)
行将编译文档而不会出现任何错误。
如果有像 ggsave()
这样的命令来保存 ggvis
图就足够了。
最佳答案
是的。
export_png
函数可以从 ggvis
对象创建 PNG 图像。
它使用node
javascript解释器,node
需要安装vega
包。
在 linux 命令行中,我可以这样做:
sudo npm -g install vega
使用节点包管理器全局安装 vega
包。我不知道您如何在 Windows 或 Mac 机器上执行此操作。
完成后,您可以:
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{geometry}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm}
\begin{document}
\chapter{Test}
\begin{figure}[H]
<< label = Plot1, fig.lp = "Plot1", fig.cap = "Test Plot" >>=
library(ggvis)
p <- mtcars %>% ggvis(x = ~wt, y = ~mpg) %>% layer_points()
export_png(p,"Plot1.png")
@
\includegraphics[width=0.8\textwidth]{Plot1.png}
\end{figure}
\end{document}
做:knit2pdf("gg.Rnw")
并得到:
请注意,您必须手动添加标题和标签。也许可以说服 Yihui 将其更好地集成到 knitr 中,或者可能有一种使用 knitr hooks 的方法。不管怎样,概念证明了...
关于r - 在 Rnw 中使用 ggvis 和 knitr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27193287/
我正在用 Bookdown 写一份报告,我有兴趣水平地复制一系列图片,并用一个描述所有图片的标题。如果我不定义 fig.cap,我会得到正确的图片,如下所示: ```{r, out.width = "
我用过dplyr对于某些分析和特定代码,完成操作大约需要 30 秒。在生成的 HTML 中,我得到了类似这样的很长的输出(再现最后几行): |=============================
我的 last two问题只是令人尴尬,但我相信这是真正的交易。我的系统是新安装的,所以除了操作系统之外的版本都是最新的:Windows 7 SP1、R-3.0.1、Lyx 2.0.6、knitr 1
我找不到将语法上可接受的 RStudio 样式折叠插入外部 R 代码文件的方法,该文件设置为从 knitr 文档中使用。或者我错过了什么。有几种方法可以做到这一点:1) 允许代码头,例如: ## @k
我有一个包含以下代码的小书本“书”: A concept map is a diagram that shows 'ideas' and the relationship between those
像这样的东西,但它不起作用: ```{r examples, engine="bash"} export EXAMPLES="example/path" ``` ```{r example1,
我是 latex 和 knitr 的新手,当我使用 echo=FALSE 时,R block 的输出有问题。下面的 .Rnw 代码按预期工作,即输出有 1. some code 2.
有没有办法使用 .Rmd 文件 直接在 Jupyter 中?换句话说,有没有办法让 jupyter 渲染这样的文件:https://github.com/yihui/knitr-examples/bl
是否可以在 markdown 文件中使用 knitr 的 pandoc() 函数和嵌入的 pandoc 配置来更改默认的 pandoc latex 模板选项? 例如,如果我在 foo.md 的开头使用
我不熟悉使用 rmarkdown 和 knitr 来制作 .docx word 文档。 rmarkdown 引用指南指出,使用 -- 给出一个破折号,而 --- 给出一个破折号。 如果我将我的 .Rm
我想知道是否有一种自动化的方法可以使评论不打印在输出中。现在,我正在使用以下内容来省略评论: >= ## load relimp package library(relimp) ## calculat
我已经根据文档在 Knitr 上添加了自定义语言引擎。 require(knitr) knit_engines$set(upper = function(options) { code <- pa
我正在使用 Rmarkdown 生成一个 PDF 文档,我想在其中手动定义图形编号。 下面是一个 block 的例子: ```{r chunk26, fig.cap = "Fig. 5.3 My fi
这可能是一个极端情况,但我正在尝试使用 knitr 创建一个投影仪演示文稿,我想在其中使用不同的公式作为函数的参数来显示代码块。我发现当使用覆盖时,代码块中的波浪号消失了。有没有办法让它们显示? 这是
我尝试编译 YiHui 的 BIG5 example (有中文内容的knitr)。我使用了 Mac OSX snowleopard、最新的 RStudio、pdfLatex(结果与 XeLatex 相
这听起来像是一个愚蠢的问题,但是当我使用 RStudio 服务器从 Rmd 文件编译 pdf 文档时,我想知道 .tex 文件保存在哪里。 我添加了 keep_tex 选项,因此 Rmd 的标题如下所
在 knitr可以在代码块中使用其他语言。例如,我们可以使用: ```{python} Some python code ``` 我们可以使用 R引擎内联`r一些R代码` 中是否可以使用其他语言?内联
例如,在编写演讲幻灯片时,我们经常会遇到这样一种情况,我们希望内联代码输出为 source code = result。 .所以例如 "foofoofoo qt(p = 0.95, df = 24)
有没有办法,在 knitr 中将 fig.cap 移动到图形上方?我需要上面的它们,以便当为某个表选择图列表的超链接时,它会导航到图。 Right now the caption and thus h
如果它在同一目录中,我可以对子文档使用以下代码。 >= @ 如果子文档不在主文档的同一目录中,我想知道如何使用子文档。预先感谢您的帮助和时间。 最佳答案 这可以被认为是一个错误。现在我已经把它修好了
我是一名优秀的程序员,十分优秀!