最近我一直在用slidify和rCharts做实验。使用slidify生成简单图表的教程是解释性的,但是我找不到关于rCharts的任何这样的教程。
例如,我知道以下内容会生成一个交互式的情节
data(mtcars)
r1<- rPlot(mpg ~ wt | am + vs, data=mtcars, type="point")
data(iris)
hair_eye = as.data.frame(HairEyeColor)
rPlot(Freq ~ Hair | Eye,color = 'Eye', data = hair_eye, type = 'bar')但是,我不知道如何使用slidify将生成的绘图合并到幻灯片中。
编辑-在有帮助的注释之后
我在Ramnath的git上看过它,我尝试了下面的方法
---
title : Practice
subtitle : makes perfect
author : Noob
job :
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
widgets : [nvd3] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
---
```{r setup, message = F, echo = F}要求(RCharts)
选项(RCHART_WIDTH= 800,RCHART_HEIGHT = 500)
Knitr::opts_chunk$set(注释= NA,结果= 'asis',tidy = F,message = F)
## NVD3 Scatterplot
```{r echo = F}数据(Mtcar)
n1 <- nPlot(mpg ~ wt,group =‘齿轮’,data =mtcar,type = 'scatterChart')
n1$print('chart1')
但最终导致了以下错误:
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'libraries/widgets/nvd3/nvd3.html': No such file or directory之后,我决定将nvd3文件夹从Ramnath的小部件直接复制到我的小部件中,希望这样可以解决问题。然而,这最终疯狂地展示了Ramnath的git页面以及我在后台的幻灯片!
该怎么办呢?我非常感谢关于如何完成这一任务的指导方针/指针/建议。并且,我希望这个问题能帮助像我这样的新手使用奇妙的rCharts。
注意:我使用的是R的标准编辑器,而不是R-studio。我觉得前者不那么杂乱。
发布于 2013-08-23 12:37:41
下面的所有说明都假设您安装了包的dev分支(slidify、slidifyLibraries和rCharts)。您可以使用install_github完成这一任务。
pkgs <- c("slidify", "slidifyLibraries", "rCharts")
devtools::install_github(pkgs, "ramnathv", ref = "dev")在幻灯片文档中包含rCharts的方法有两种,下面的图层说明了这两种方法。如果您在代码块中打印一个图,就像在R控制台中那样,slidify会自动检测到您正在针织品会话中运行它,因此将生成的html保存到iframe并将其嵌入到面板中。或者,您可以内联地指定图表,在这种情况下,您必须使用n1$show("inline"),并在YAML前端事项中包括ext_widgets: {rCharts: libraries/nvd3}。
iframe方法是默认的和推荐的方法,以避免各种javascript文件和css之间的冲突。内联方法在几个rCharts库中确实运行良好,但是在使用之前要确保检查。
---
title : rCharts Integration
ext_widgets : {rCharts: libraries/nvd3}
mode: selfcontained
---
## NVD3 Plot Inline
```{r nvd3plot, results = 'asis', comment = NA, message = F, echo = F}要求(RCharts)
n1 <- nPlot(mpg ~ wt,data =mtcar,type = 'scatterChart')
N1$show(‘内联’)
---
## NVD3 Plot Iframe
```{r nvd3plot2, results = 'asis', comment = NA, message = F, echo = F} 要求(RCharts)
n1 <- nPlot(mpg ~ wt,data =mtcar,type = 'scatterChart')
n1
https://stackoverflow.com/questions/18391015
复制相似问题