Julia using StatsPlots.jl for grouped bar plot. How to get a legend on the bar plot?

963 views Asked by At

I'm trying to plot some data using Julia, but I'm quite new to Data visualisation in Julia. I have code that looks like this:

x_data = [5 10;
        15 20]

groupedbar( ["0.2", "0.8"], x_data, xlabel = "X-axis", 
    ylabel="Y-axis")

Each x-value (0.2 and 0.8) will have 2 bars each which are different colours. I am trying to create a legend for these colours.

I have tried the following code but it for some reason plots the data incorrectly (only plots the first 2 data points):

groupedbar( ["0.2", "0.8"], x_data, xlabel = "X-axis", 
    ylabel="Y-axis", group = ["Category 1", "Category 2"])
1

There are 1 answers

4
Bogumił Kamiński On

Is this what you want?

groupedbar(["A", "A", "B", "B"], [4, 1, 2, 3], group = ["x", "y", "x", "y"])

(note that all three arguments have the same length)