Improved Stacked Bar Graph

From J Wiki
Jump to navigation Jump to search

Improved Stacked Bar Graph

I have updated the jzplot class to include an additional type of stacked bar graph, "sbarn", that accepts negative values.

Examples

load'plot'
   (],:|.)@:(,|.@:-) i.5
0  1  2  3  4 _4 _3 _2 _1 0
0 _1 _2 _3 _4  4  3  2  1 0

    'sbarn' plot (],:|.)@:(,|.@:-) i.5

Sbarn1.png

    'sbarn; barwidth 1' plot (],:|.)@:(,|.@:-) i.5

Sbarn2.png

Setting the EDGECOLOR option to -1 draws the edges the same colors as the bars.

   'sbarn;barwidth 1;edgecolor _1' plot_jzplot_ (],:|.)@:(,|.@:-) i.5

Sbarn3.png

Here is a more realistic example showing the changing contribution of each series plotted with the total.

    dat=: |:(+0.5-[:?0$~#)^:(<100) 0 _4 4 0
    pd 'new'
    pd 'type sbarn; edgecolor _1; barwidth 1;xtic 10 2'
    pd  dat
    pd 'show'
    pd 'type line;color 0 0 0; pensize 2;xtic 10 2'
    pd +/dat
    pd 'show'

Sbarn4.png

Plot Class

The updated jzplot class is File:Jzplot.ijs.

jzplot subclass

I have attempted to subclass the jzplot class instead of changing its source. The subclass script is File:Tcplot.ijs. However, this is not working. I don't have much experience working with classes in J; if anyone can figure out why it doesn't work please let me know and update the script.