Gadfly.jl icon indicating copy to clipboard operation
Gadfly.jl copied to clipboard

Multiple Category Axis

Open alecloudenback opened this issue 6 years ago • 4 comments

Feature Request: Plotting with different groups/layers on the axis.

https://peltiertech.com/chart-with-a-dual-category-axis/

alecloudenback avatar Sep 07 '19 00:09 alecloudenback

For the plot linked above, you can do:

using DataFrames, Gadfly
groups =  vcat(fill.(["Mechanical", "Electrical", "Hydraulic"], [3,5,3])...)
components = ["Gear", "Bearing", "Motor", "Electrical\nSwitch", "Plug", "Cord", "Fuse", 
    "Bulb", "Hydraulic\nPump", "Leak", "Seals"]
rates = [11, 8, 3, 19, 12, 11, 3, 2, 4, 3, 1]
df = DataFrame(group = groups, component=components, rate=rates)

p1 = plot(df, x=:component, y=:rate, color=:group, Geom.bar, Theme(bar_spacing=1mm),
    Guide.xlabel("Mechanical\t\t\t\tElectrical\t\t\tHydraulic  "))

iss1310a

If the "components" were the same for the different groups, try Geom.subplot_grid. Also example here.

Mattriks avatar Sep 07 '19 12:09 Mattriks

@alecloudenback if the example above solves your problem can you please close this issue? thanks.

bjarthur avatar Oct 20 '19 12:10 bjarthur

Thanks! I appreciate getting it to work on the one example linked, but I thought that since the workaround was very manual that it would still be nice to have better support for this type of plotting built in.

alecloudenback avatar Oct 20 '19 15:10 alecloudenback

Here's what currently happens with Geom.subplot_grid(free_x_axis=true):

# df same as above
plot(df, x=:component, y=:rate, xgroup=:group, color=:group, 
    Geom.subplot_grid(Geom.bar, free_x_axis=true),
    Theme(bar_spacing=1mm), Guide.xlabel(nothing)
    )

iss1310b

The issue is that the subplot x scales are not proportional (so the bars are of different width). Thus this is the same issue as #1093.

Mattriks avatar Jan 22 '20 21:01 Mattriks