私はplotlyを使ってggplot2チャートを変換し、それらをknitr html出力に入れています。 ここにレポートの作業コピーがあります。 http://rpubs.com/kausti/NSEFO-23-Mar-2016 最初のグラフはプロットチャートであり、次のグラフはグラフではありません。私はそれらを陽気な図表にしたいが、私は立ち往生している。forループのプロットチャート
以下のコードでは、plotChart関数はggplot2プロットを返します。このコードは機能します!私はprint(ggplotly(p))
に最後のprint文を変更した場合
for (tick in tradeOps$ticker)
{
tmpDF = filter(tradeOps, ticker == tick)
p = plotChart(tick = tick,Entry = tmpDF$Entry, Target = tmpDF$Target, SL= tmpDF$SL, TradeType = tmpDF$TradeType, data = wd)
p = p + annotate("text", x = as.Date(tmpDF$Date)+30, y = tmpDF$Entry, label = tmpDF$Entry, colour = "blue")
p = p + annotate("text", x = as.Date(tmpDF$Date)+30, y = tmpDF$Target, label = tmpDF$Target)
p = p + annotate("text", x = as.Date(tmpDF$Date)+30, y = tmpDF$SL, label = tmpDF$SL)
print(p)
}
今ではただのhtmlでグラフを印刷されません。 コードはknitrの外側で完全に動作します。
また、print(ggplotly(p))
は完全にループ外で動作します。 何か不足していますか?
EDIT:以下再現例を含む
。 以下は私のrmdファイルです。
---
title: "tmp"
output: html_document
---
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=6}
library(ggplot2)
library(plotly)
library(dplyr)
s = NULL
a = data.frame(id = 1:15,x = 2:16, y = 15:1, z = c(rep("a",5),rep("b",5),rep("c",5)))
for(i in unique(a$z)){
s = a[a$z == i,]
print(ggplot(s,aes(x = x, y = y)) + geom_point())
}
```
これは3つのグラフを表示する出力htmlで完全に機能します。 最後のprint文を print(ggplotly(ggplot(s,aes(x = x, y = y)) + geom_point()))
に変更するだけで、エラーなしで空白のhtmlが生成されます。
library(ggplot2)
library(plotly)
library(dplyr)
s = NULL
a = data.frame(id = 1:15,x = 2:16, y = 15:1, z = c(rep("a",5),rep("b",5),rep("c",5)))
for(i in unique(a$z)){
s = a[a$z == i,]
print(ggplotly(ggplot(s,aes(x = x, y = y)) + geom_point()))
}
は、任意の助けに感謝かかわらず、端末で同じコードを実行
は完璧に動作します。
おかげで、 Kaustubh
あなたの投稿が再現可能ではありません。とにかくポストにデータを追加できますか? – MLavoie
@MLavoie再現可能な例を含めるように質問を編集しました。ありがとう。 –