Greetings:
I am vertically stacking two bar plots from PlotlyJS, which can be interpreted as a historical decomposition of output and the Solow residual over the business cycle into various shocks. The problem is that duplicated entries are generated in the legend. I believe using traces rather than plots may be the way to resolve this issue, but I am not sure how to implement it. The code I have is as follows:
time = range(Date(1966, 1, 1), step=Dates.Quarter(1), stop=Date(2021, 12, 31))
x = matopen("hist_dec.mat")
hist_dec = read(x, "hist_dec")
labels = ["Output", "Solow residual"]
figs = [PlotlyJS.plot() for _ in 1:2]
for i in 1:2
hist_dec_i = hist_dec[i, :, :]
# Transpose and drop measurement errors
hist_dec_i = hist_dec_i'
hist_dec_i = convert(DataFrames.DataFrame, hist_dec_i)
hist_dec_i = hist_dec_i[!, 1:7]
rename!(hist_dec_i, [:Consumption_tech, :Investment_tech, :Entry_tech,
:Intratemporal_preference, :Shopping_disutility, :Discount_factor, :Labor_supply])
hist_dec_i[!, :date] = time
long_df = DataFrames.stack(hist_dec_Y, Not([:date]), variable_name=:shock, value_name=:share)
figs[i] = PlotlyJS.plot(long_df, kind="bar", x=:date, y=:share, color=:shock, Layout(title=labels[i],
barmode="stack"))
end
fig_hist = [figs[1]; figs[2]]
relayout!(fig_hist, title_text="Historical decomposition", barmode="stack", color="shock")
display(fig_hist)
PlotlyJS.savefig(fig_hist, "fig_hist.pdf")
I attach the generated figure. Also, the information comes from a .mat file generated in another program, which I cannot attach here. Please let me know if it is necessary to provide the file in some other format.