2016-04-17 29 views
2

私はシャイニーと私のアニメーションスライダープロジェクトに取り組んできましたは、私が後にしたことを持っていますが、それほどではありません。連続した各グラフをアニメーション化されたシーケンスで表示するのではなく、すべてのデータ(シーケンス化されていない)でグラフを表示しているようです。私は私のエラーがどこにあるのかははっきりしていませんが、それは反応関数呼び出しまたはサーバーセクションのrenderPlot関数呼び出しにあると思われます。私はWebを検索しようとしましたが、別の場所に別のコードブロックを配置しようとしましたが、Shinyでアニメーションを動作させることができません。最終的に数値月(1,2,3 ...)をより明瞭にするために日付オブジェクトに変更したいと思いますが、アニメーションが動作した後にそのオブジェクトに取り組みます。Rベースのグラフィックスやggplotでアニメーション散布図を使用すると光沢がありますか?

私はgoogleVic、gvisMotionChart、Shinyを使用してこのデータのモーションチャートを正常に取得できましたが、私はバブルチャートの色やバブルのサイズを制御できませんでした。オーバーラップのためGoogleのバブルチャートのデフォルトサイズよりもはるかに小さい一定のサイズ)。だから、私はRの基本グラフィックスやggplotを使ってこのアニメーションを実現したいと考えています。ここで

は、データの小さなセットは、私が使用しているものを表現するためである。ここでは
d1 <- data.table( id = 1:21, 
      Region = rep(c("R1","R2","R3"), each=7), 
      Month = 1, 
      Spend = round(runif(21,100,500)), 
      Age = round(runif(21,72,100)), 
      Color = rep(c("#E69F00","#D55E00","#009E73"),each=7)) 
d2 <- copy(d1) 
d2[,Month:=Month+1][,Age:=Age+1][,Spend:=Spend+round(runif(21,0,4))] 
d3 <- copy(d2)    
d3[,Month:=Month+1][,Age:=Age+1][,Spend:=Spend+round(runif(21,0,4))]     
d4 <- copy(d3)    
d4[,Month:=Month+1][,Age:=Age+1][,Spend:=Spend+round(runif(21,0,4))] 
d5 <- copy(d4)    
d5[,Month:=Month+1][,Age:=Age+1][,Spend:=Spend+round(runif(21,0,4))] 
d6 <- copy(d5)    
d6[,Month:=Month+1][,Age:=Age+1][,Spend:=Spend+round(runif(21,0,4))] 
d7 <- copy(d6)    
d7[,Month:=Month+1][,Age:=Age+1][,Spend:=Spend+round(runif(21,0,4))] 
d8 <- copy(d7)    
d8[,Month:=Month+1][,Age:=Age+1][,Spend:=Spend+round(runif(21,0,4))] 
dat <- rbindlist(list(d1,d2,d3,d4,d5,d6,d7,d8)) 

はアニメーションが

saveGIF({ 
for(i in 1:8){ 
    plot(dat[Month==i,Age],dat[Month==i,Spend],col=dat[Month==i,Color], 
     pch=16, xlim=c(min(dat$Age)*.95,max(dat$Age)*1.1), 
     ylim=c(min(dat$Spend)*.95,max(dat$Spend)*1.1), 
     xlab="Age in Months",ylab="Dollars", las=1, cex.axis=.7) 
    legend("topright",inset=.05,c("Reg 1","Reg 2","Reg 3"), 
     pch=16,col=c("#E69F00","#D55E00","#009E73"), 
     cex=.8) 
    ani.pause() 
} 
}, interval = 0.25, ani.width = 750, ani.height = 550) 

これは、基本グラフィックスでどのように見えるかを示すためにアニメーションGIFである私現在非稼働シャイニーコード

library(shiny) 
library(ggplot2) 

# Shiny app with slider and animation 

# ui section 
ui = fluidPage(

    # Title 
    titlePanel("Spend vs Age by Region"), 

    # Sidebar with slider and controls for animation 
    sidebarLayout(

     # sidebar with slider 
     sidebarPanel(
      # Slider with looping 
      sliderInput("theMonth", "Month", 1, 8, 1, step = 1, 
       animate=animationOptions(interval=1000, loop = T, 
        playButton = T, pauseButton = T)) 
     ), 

     # Show the animated graph 
     mainPanel(
      plotOutput(outputId="case_age_plot") 
     ) 
    ) 
) 

# server section 
server = function(input, output) { 

    # Reactive expression to create data frame and graph 
    aniGraph <- reactive({ 

     # subset the data frame into the portion that has the data for the 
     # graph in the animation sequence 
     dat[Month==input$theMonth,] 

     # create the graph 
     plot(dat[,Age],dat[,Spend],col=dat[,Color], 
      pch=16, xlim=c(min(dat$Age)*.95,max(dat$Age)*1.1), 
      ylim=c(min(dat$Spend)*.95,max(dat$Spend)*1.1), 
      xlab="Age in Months",ylab="Dollars", las=1, cex.axis=.7) 
     legend("topright",inset=.05,c("Reg 1","Reg 2","Reg 3"), 
      pch=16,col=c("#E69F00","#D55E00","#009E73"),cex=.8) 
    }) 

    # Show the graph 
    output$case_age_plot <- renderPlot({ 
     aniGraph() 
    }) 
} 

# run the app 
runApp(list(ui = ui, server = server)) 

誰かが解決策や考えを持っているなら、私は感謝します。

答えて

3

datのサブセットを保存していないという問題がありました。 GIFアニメーションと同じアニメーションを取得するようにコードを少し修正しました。

library(shiny) 
library(ggplot2) 

# Shiny app with slider and animation 

# ui section 
ui = fluidPage(

    # Title 
    titlePanel("Spend vs Age by Region"), 

    # Sidebar with slider and controls for animation 
    sidebarLayout(

    # sidebar with slider 
    sidebarPanel(
     # Slider with looping 
     sliderInput("theMonth", "Month", 1, 8, 1, step = 1, 
        animate=animationOptions(interval=1000, loop = T, 
              playButton = T, pauseButton = T)) 
    ), 

    # Show the animated graph 
    mainPanel(
     plotOutput(outputId="case_age_plot") 
    ) 
) 
) 

# server section 
server = function(input, output) { 

    # Reactive expression to create data frame and graph 
    aniGraph <- reactive({ 

    # subset the data frame into the portion that has the data for the 
    # graph in the animation sequence 

    # Save subset of 'dat' and pass it to the plot 
    dat_sub <- dat[Month==input$theMonth,] 

    # create the graph 
    plot(dat_sub[,Age],dat_sub[,Spend],col=dat_sub[,Color], 
     pch=16, xlim=c(min(dat$Age)*.95,max(dat$Age)*1.1), 
     ylim=c(min(dat$Spend)*.95,max(dat$Spend)*1.1), 
     xlab="Age in Months",ylab="Dollars", las=1, cex.axis=.7) 
    legend("topright",inset=.05,c("Reg 1","Reg 2","Reg 3"), 
      pch=16,col=c("#E69F00","#D55E00","#009E73"),cex=.8) 
    }) 

    # Show the graph 
    output$case_age_plot <- renderPlot({ 
    aniGraph() 
    }) 
} 

# run the app 
runApp(list(ui = ui, server = server)) 
+1

うわー、ありがとう。 –

関連する問題