2016-09-26 23 views
0

光るアプリでPlotlyグラフをレンダリングしようとしています。基本グラフは生成されていますが、軸の書式設定はできません。以下のようなレイアウトで、Plotly Webアプリケーションで目的のグラフオプションを取得することができます。renderPlotly(Shiny r)内で詳細なレイアウトを指定する方法

"layout": { 
     "autosize": true, 
     "height": 831.625, 
     "hovermode": "x", 
     "width": 1480, 
     "xaxis": { 
      "autorange": true, 
      "hoverformat": "%Y-%m", 
      "range": [ 
       1356978600000, 
       1391193000000 
      ], 
      "rangeselector": { 
       "buttons": [ 
        { 
         "label": "reset", 
         "step": "all" 
        }, 
        { 
         "label": "#1", 
         "step": "month" 
        } 
       ] 
      }, 
      "tickformat": "%Y-%m", 
      "tickmode": "auto", 
      "tickprefix": "", 
      "title": "B", 
      "type": "date" 
     }, 
     "yaxis": { 
      "autorange": true, 
      "range": [ 
       -19.888888888888893, 
       397.8888888888889 
      ], 
      "title": "A", 
      "type": "linear" 
     } 
    } 

光沢のあるコード内でこのレイアウトを指定する際に問題があります。 titleのような単純なオブジェクトの場合は、以下のように動作します。

output$plot <- renderPlotly({ 
new_plot <- plot_ly(plot_data, x = plot_data$FY_Month, y = plot_data$Booking_Amount , name = "Test Data (Actual)") 

new_plot <- layout(new_plot,title = "Random Title") 
new_plot 
}) 

どのように複雑なx軸とy軸のレイアウトを教えてください。

答えて

0

自分自身の質問に対する回答が見つかりました。

x_axis <- list(
     title = "Fiscal Year/Month", 
     autorange = "true", 
     hoverformat = "%Y-%m", 
     tickformat = "%Y-%m", 
     tickmode = "auto", 
     type = "date" 
    ) 
y_axis <- list( 
     title = "A", 
     type ="linear" 
) 


output$plot <- renderPlotly({ 
new_plot <- plot_ly(plot_data, x = plot_data$FY_Month, y = plot_data$Booking_Amount , name = "Test Data (Actual)") 

new_plot <- layout(new_plot,title = "Random Title") 
new_plot <- layout(new_plot, xaxis=x_axis, yaxis = y_axis) 
new_plot 
}) 

同様に、他の形式も指定できます。次のリファレンスを使用しました。 Plotly R API reference doc for Axes Labels

関連する問題