您可以通过使用添加另一个跟踪来实现这一点
type='scatter'
和
mode='lines'
(我给它起了个名字
life.cycle
)并在
layout(...)
:
plot_ly(results2, x = ~Group.1, y = ~RETQLIQ,
type = 'bar', name = 'Retirement (Pension/IRA)') %>%
add_trace(x = ~Group.1, y = ~life.cycle,
type = 'scatter', mode = 'lines', name = 'life.cycle',
yaxis = 'y2', line = list(color = 'orange')) %>%
layout(title = "Pensions Wealth", barmode = 'stack',
xaxis = list(title = "Net Worth"),
yaxis = list(side="left", title = 'Millions'),
yaxis2 = list(side = 'right', overlaying = "y", title = '',
showgrid = FALSE, zeroline = FALSE))