juliagadfly

How do I sort a bar chart in ascending or descending order in Julia's Gadfly? (Does anyone know a less hacky way?)


I've made a dict-of-counts style df to make a barplot from and am interested in sorting the bars in descending order by size. In the R world I'd do something like this and was wondering 1) what a tidy way to do this would be and 2) if something like it existed in Gadfly.


Solution

  • df = DataFrame(
    list = ["E", "E", "E", "E", "E","B", "B", "B", "B",
        "C", "C", "C", "D", "D", "D","A"]
    )
    
    
    p1 = plot(df, x=:list, Geom.histogram)
    p2 = plot(df, x=:list, Geom.histogram,  Scale.x_discrete(levels=["A","D","C","B","E"]) )
    
    

    enter image description here

    See the Gadfly tutorial