2017-10-25 14 views
1

플로팅 차트와 막대 차트를 중첩하여 (중요한 날짜를 나타내는 수직선으로) 두 개의 제로 라인이 오프셋 된이 문제가 발생했습니다 같은 줄에있는 대신에. 난 내에서 overlaying = 'y' 옵션으로 주위를 망쳐 봤는데 세 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