Last active
December 27, 2015 22:09
-
-
Save nezuQ/7396665 to your computer and use it in GitHub Desktop.
RStudioのR PresentationsでrChartsを使う方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RStudioのR PresentationsでrChartsを使う方法 | |
======================================================== | |
author: nezuq | |
date: 2013/11/10 | |
width: 1440 | |
height: 900 | |
transition: fade | |
R Presentations + rChartsの例 | |
======================================================== | |
<style> | |
.rChart { | |
display: block; | |
height: 400px; | |
} | |
</style> | |
```{r results = 'asis', echo=F} | |
require(rCharts) | |
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male") | |
n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarChart") | |
n1$print('mychart1', include_assets = TRUE, cdn = TRUE) | |
``` | |
*マウスを棒に当てるとアニメーションが動きます。 | |
失敗コード1 | |
======================================================== | |
最もシンプルな考え方で実装したコードはこれだが、 | |
見事に失敗した。 | |
最後のn1はHTMLコードを返却するが、 | |
最終的なコード上ではテキストとして解釈された。 | |
``` | |
''' {r} | |
require(rCharts) | |
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male") | |
n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarChart") | |
n1 | |
''' | |
``` | |
失敗コード2 | |
======================================================== | |
Rコードから出力された結果をHTMLとして解釈させる事にした。 | |
しかし、外部JSライブラリがない為に動作しなかった。 | |
``` | |
'''{r results = 'asis'} | |
require(rCharts) | |
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male") | |
n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarChart") | |
n1 | |
''' | |
``` | |
失敗コード3 | |
======================================================== | |
rChartsの機能で「CDNからJSライブラリを呼び出すコード」も一緒に出力できた。 | |
描画には成功したが、チャートが潰れて表示された。 | |
``` | |
'''{r results = 'asis'} | |
require(rCharts) | |
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male") | |
n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarChart") | |
n1$print('mychart1', include_assets = TRUE, cdn = TRUE) | |
''' | |
``` | |
成功コード | |
======================================================== | |
チャート用のCSSを用意したら、正常に表示された。 | |
``` | |
<style> | |
.rChart { | |
display: block; | |
height: 400px; | |
} | |
</style> | |
'''{r results = 'asis'} | |
require(rCharts) | |
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male") | |
n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarChart") | |
n1$print('mychart1', include_assets = TRUE, cdn = TRUE) | |
''' | |
``` | |
* 上記コード内のシングルコーテーション(')はグレイヴアクセント(`` ` ``)に置換する事。 | |
感想 | |
======================================================== | |
英語文献を探しても実装方法が出てこないとかマジ苦行! | |
パトラッシュ、僕はもう疲れたよ。 | |
このスライド全体のコードはこちら。 | |
<https://gist.github.com/nezuQ/7396665> | |
--end-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment