2015-09-03 173 views
1

enter image description here我創建閃亮的一本筆記本,我發現使用附加plotly當以下問題:閃亮與plotly

Data_xts=Data_xts() #this return a reactive data.frame. fm_timeseries is already formated as POSIXct and has the following format : YYYY-MM-DD hh:mm:ss 
plot_ly(x=Data_xts$fm_timeseries, y = Data_xts$Open,name='Stock Prices',showlegend = FALSE) %>% 
add_trace(x=Data_xts$fm_timeseries, y = Data_xts$UKX_open, yaxis='y2') %>% 
add_trace(x=Data_xts$fm_timeseries, y = Data_xts$TotalNews, yaxis='y3') %>% 
layout(yaxis=list(title='Stock Price'), 
yaxis2=list(title='Market Index', overlaying = "y",side='right',position=.97,tickfont = list(size = 8)), 
yaxis3=list(title='Total News', overlaying = "y",side='right',anchor='free', tickfont = list(size = 8),position=1), 
xaxis=list(title='Time Series') , showlegend = TRUE) 

這裏是一對夫婦,我創辦的問題:

  • 時間戳不顯示爲時間戳(我甚至試圖從plotly和R的簡單示例,並驗證它不能在Shiny上工作)。實際上,時間戳被分類爲字符串,並且不能將xaxis標記視爲這樣的結果。
  • 挑戰在同一軸上獲取yaxis2和3而不與圖表本身重疊。

爲了解決這個奇蹟,如果有,我們可以進入x軸(試過type='date'但沒有工作)的格式,並在右側的y軸,如果有任何類型的自動排列(2 3)。

+0

修改邊距,如下:https://stackoverflow.com/questions/39726146/how-do-you-increase-the-space-between-the-axis-labels -and軸標題-在-R-使用/ 40771909#40771909 –

回答

0

嘗試使用「因子」。 所以在你的例子:

plot_ly(x= ~factor(Data_xts$fm_timeseries), y = ~Data_xts$Open, name='Stock Prices',showlegend = FALSE)