2016-11-16 75 views
1

我试图在R滑动中生成谷歌运动图表。我在网上查了很多例子,似乎有些人已经成功将Google运动图嵌入到R滑动幻灯片中。然后当我使用类似的代码尝试我自己的时候,它给了我空白的结果。我也用同样的方法制作一个谷歌饼图和它运作良好(饼图显示在绘图区)gvisMotionChart在R中返回空格plotify

下面是我下面的简化代码(这里我用的是水果数据集就像所有其他演示):

--- 
title: "Title" 
author: "Me" 
date: '`r format(Sys.time(), "%d %B, %Y")`' 
output: 
    ioslides_presentation: 
    incremental: yes 
    transition: default 
    widescreen: yes 
    slidy_presentation: 
    incremental: yes 
job: Job Title 
license: by-nc-sa 
mode: selfcontained 
hitheme: tomorrow 
highlighter : highlight.js 
subtitle: Subtitle 
framework: io2012 
widgets: [] 

--- 

## GoogleVis Motion chart example 

```{r motionchartcode1, results='asis', warning=FALSE, comment=NA} 
library(googleVis) 
options(gvis.plot.tag='chart') 
M <- gvisMotionChart(Fruits, 'Fruit', 'Year', 
     options=list(width=400, height=350)) 
#plot(M) 
print(M, tag = 'chart') 
``` 

--- 

## GoogleVis Pie chart example 

```{r motionchartcode, results='asis'} 
library(googleVis) 
options(gvis.plot.tag='chart') 
Pie <- gvisPieChart(CityPopularity, 
        options=list(width=400, height=200)) 
print(Pie, tag = 'chart') 

``` 

然后我用slidify("demo.Rmd")将它编译成html文件。第一张幻灯片没有绘制任何绘图,而是绘制了一个空白区域。

我不确定哪个部分影响到这个结果:---部分中的设置,r降级块或我的浏览器环境中的选项?

希望有人可以给我的想法。

回答

0

R中的plot命令使用内部R http帮助服务器来克服此限制。

这里是我如何克服的:

Go to 

http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html 

Click on the dropbox which says 'Edit location' and choose 'add location' 

Click 'browse for folder or browse for file' 

Choose the folder (or file) in which was your saved html output 

Click OK 

您也可以修改您的代码,例如我做:

suppressPackageStartupMessages(library(googleVis)) 

options(gvis.plot.tag='chart') 

M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year") 

plot(M1) 

print(M1, file="myGoogleVisChart.html") 

现在打开你的googleVis的HTML文件,它应该成功显示。

事实上,您从所选文件夹中打开的任何googleVis文件也会按照您的预期显示。

请注意我正在使用MS Internet Explorer并且它询问我在能够查看上面的输出之前激活ActiveX,并且它正在为我工​​作。

不过,如果你不能看到那么也请检查:

https://cran.r-project.org/web/packages/googleVis/vignettes/googleVis.pdf