Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Category Axis #1310

Open
alecloudenback opened this issue Sep 7, 2019 · 4 comments
Open

Multiple Category Axis #1310

alecloudenback opened this issue Sep 7, 2019 · 4 comments

Comments

@alecloudenback
Copy link

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

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

@Mattriks
Copy link
Member

Mattriks commented Sep 7, 2019

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.

@bjarthur
Copy link
Member

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

@alecloudenback
Copy link
Author

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.

@Mattriks
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants