Plot with double (or triple) x ticks labels on Julia like Excel Pivot Chart

82 Views Asked by At

I want to plot something with doulble x ticks labels one for the item name and other for the purchase month

Month Item Price
Feb Tomatoe 15
Feb Cockies 10
Feb Juice 20
Feb Orange 13
Mar Cake 11
Mar Potato 30
Mar Juice 13

I tried using twiny() but I want the labels on the same side. Excel Pivot Chart does the work but the performance is very low with huge amount of data.

Pivot Chart in Excel

2

There are 2 best solutions below

0
Igor Hołowacz On

You can use groupedbar() from StatsPlots to get something like that:

using StatsPlots

values = [15, 10, 20, 13, 11, 30, 13]
item = ["tomato", "cookies", "juice", "orange", "cake", "potato", "juice"]
Month = ["Feb", "Feb","Feb","Feb","Mar","Mar","Mar"]

groupedbar(item, values, group = Month)
0
giantmoa On

using StatisticalGraphics.jl

using StatisticalGraphics, InMemoryDatasets
ds=Dataset(values = [15, 10, 20, 13, 11, 30, 13],
item = ["tomato", "cookies", "juice", "orange", "cake", "potato", "juice"],
Month = ["Feb", "Feb","Feb","Feb","Mar","Mar","Mar"])

sgplot(gatherby(ds,:Month), 
                             Bar(x=:item,response=:values),
                             layout=:row,
                             linkaxis=:y,
                             proportional=true,
                             headerorient=:bottom,
                             headercolname=false,
                             headeroffset=30,
                             panelborder=false,
                             columnspace=0,
                             xaxis=Axis(title=""),
                             yaxis=Axis(title="Total")
  )

enter image description here