2017-10-25 16 views
1

私は線グラフと棒グラフをプロットして重ねて表示しています(重要な日付を示す縦線で)、2つのゼロラインがオフセットされている同じ行の代わりに私はオプションをlayoutの範囲で使いこなしてみましたが、3つのtraceコンポーネントの順序を変更しようとしましたが、何も役立たないようです。任意のアイデアを修正する方法?以下は、ダミーデータと私のコードは次のとおりです。二重軸プロット上の異なるレベルのゼロリンをプロットする

date <- seq(as.Date("2015/6/1"), by = "month", length.out = 19) 
wires_mnth <- c(rep(0,8),100000,750000,1200000,2500000,3100000,5500000,7500000,8000000,9900000,11300000,11000000) 
wires_cnt <- c(rep(0,8),100,200,250,325,475,600,750,800,1000,1150,1200) 
data <- data.frame(date, wires_mnth) 

plot_ly(data) %>% 
add_trace(x = ~date, y = ~wires_cnt, type = 'bar', name = 'Wires Count', 
    yaxis = 'y2', opacity = .5) %>% 
add_trace(x = ~date, y = ~wires_mnth, type = 'scatter', mode = 'lines', name 
    = 'Monthly Wires') %>% 
add_trace(x = c(2016,2016), y = c(0, 12000000), type = 'scatter', mode = 
    "lines", name = 'Sanctions Removed') %>% 

layout(title = 'Monthly Aggregate Wire Transfers to Iran', 
    xaxis = list(title = ''), 
    yaxis = list(side = 'left', title = 'Wire Amounts (USD)', showgrid = 
     FALSE, zeroline = FALSE), 
    yaxis2 = list(side = 'right', overlaying = 'y', title = 'Wires Count', 
     showgrid = FALSE, zeroline = FALSE) 
    ) 

enter image description here

答えて

1

あなたはあなたのlayoutrangemode='nonnegative'を追加したり、指定することができます(また、ボーナスポイントは、あなたは私の伝説重複-y2axis問題を修正することができる場合) を手動でrange=list(0, max(wires_mnth)経由で送信します。

あなたのボーナスに関する質問では、凡例のx-positionを設定することができます。 legend = list(x = 1.2)

enter image description here

+0

plotlyウィザード! – rmbaughman

関連する問題