# Bar and line charts combined in PlotlyJS

**URL:** <https://discourse.julialang.org/t/bar-and-line-charts-combined-in-plotlyjs/84870>\
**Category:** Visualization\
**Tags:** question\
**Created:** [July 27, 2022, 12:03pm UTC](https://discourse.julialang.org/t/bar-and-line-charts-combined-in-plotlyjs/84870 "2022-07-27T12:03:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mariana](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariana/32/15064_2.png) [@Mariana](https://discourse.julialang.org/u/Mariana)\
**Post date:** [July 27, 2022, 12:03pm UTC](https://discourse.julialang.org/t/bar-and-line-charts-combined-in-plotlyjs/84870/1 "2022-07-27T12:03:09Z")

</div>

Hello!

I’m trying to plot a bar chart and a line chart combined in the same double y-axis plot, using PlotlyJS, by running the following code:

```julia
fixed_cost = [791.57;773.16;765.58;758.15;750.86;743.71;736.69;729.81;723.05;716.42;709.91]

plot(
    [
        scatter(x = 0:0.01:0.1, y = [0;0;0;0;0;0;0;0;0;0.008;0.0394], name = "avg_penalty_cost"),
        scatter(x = 0:0.01:0.1, y = [0;0;0;0;0;0;0;0;0;0.1602;0.7873], name = "cvar_penalty_cost", marker_color = "MediumPurple"),
        bar(x = 0:0.01:0.1, y = fixed_cost, name = "fixed_cost", text = fixed_cost, textposition = "auto", marker_color = "LightSkyBlue", yaxis = "y2"),
    ],
    Layout(
        title_text = "Sensitivity Analysis",
        xaxis = attr(title = "δᴱ", tickmode = "linear", tick0 = 0, dtick = 0.01),
        yaxis_title_text = "Penalty Cost (\$)",
        yaxis2 = attr(
            title = "Fixed Cost (\$)",
            showlegend=false,
            overlaying = "y",
            side = "right"
        ), 
        legend = attr(
            x = 1,
            y = 1.02,
            yanchor = "bottom",
            xanchor = "right",
            orientation = "h"
        )

    )
)

```

The plot I obtained has the correct axis, however, the line chart is behind the bar chart, and I wish it was the opposite (I’d like the bar chart to be behind the line chart).

Any ideas on how I can fix that?

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 27, 2022, 12:45pm UTC](https://discourse.julialang.org/t/bar-and-line-charts-combined-in-plotlyjs/84870/2 "2022-07-27T12:45:14Z")

</div>

Your bars cover the lines because in `yaxis2` definition you have

```julia
overlaying = "y"

```

Comment out this line, and add to Layout:

```julia
yaxis_overlaying="y2",

```

---

<div class="post-metadata">

**Author:** ![Mariana](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariana/32/15064_2.png) [@Mariana](https://discourse.julialang.org/u/Mariana)\
**Post date:** [July 27, 2022, 12:55pm UTC](https://discourse.julialang.org/t/bar-and-line-charts-combined-in-plotlyjs/84870/3 "2022-07-27T12:55:40Z")

</div>

Thank you very much! Now it looks exactly how I wanted it!
