2016-11-16 73 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