Gadfly.jl
Gadfly.jl copied to clipboard
Multiple Category Axis
Feature Request: Plotting with different groups/layers on the axis.
https://peltiertech.com/chart-with-a-dual-category-axis/
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 "))

If the "components" were the same for the different groups, try Geom.subplot_grid. Also example here.
@alecloudenback if the example above solves your problem can you please close this issue? thanks.
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.
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)
)

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.