Jsoftware
High-Performance Development Platform

Stacked Bar Chart

View: New views
20 Messages — Rating Filter:   Alert me  

Stacked Bar Chart

by Thomas Costigliola-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I would like to create a chart like the one in the link below. It is a
stacked bar chart with no space between the bars. Plot doesn't seem to
allow negative values in stacked bar charts. Is there any work around
for this? There would also need to be a way to draw the bars next to
each other as in a histogram.

The given plot was produced with R; it has an incredibly flexible
plotting package.

http://www.jsoftware.com/jwiki/ThomasCostigliola
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by bill lam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 06 Nov 2009, Thomas Costigliola wrote:
> The given plot was produced with R; it has an incredibly flexible
> plotting package.

Not exactly an answer.  There are plot packages (eg. goffice) for gtk+
(untested).

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by James Foit :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I was googling 'tacit programming', found this:
http://en.wikipedia.org/wiki/Tacit_programming
And noticed near the top of the page this line:
"Outside of the APL and J communities, tacit programming is referred to as point-free style[1], or more pithily as pointless programming."

Someone with a wiki account may want to remove the final clause.  Innuendo like that can destroy all that u guys work for.

> Date: Sat, 7 Nov 2009 11:08:57 +0800
> From: bbill.lam@...
> To: programming@...
> Subject: Re: [Jprogramming] Stacked Bar Chart
>
> On Fri, 06 Nov 2009, Thomas Costigliola wrote:
> > The given plot was produced with R; it has an incredibly flexible
> > plotting package.
>
> Not exactly an answer.  There are plot packages (eg. goffice) for gtk+
> (untested).
>
> --
> regards,
> ====================================================
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
     
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by Björn Helgason :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It is actually more just funny comment.

From the same page

"APL (family)
In J one can see the same sort of point-free code in a function
designed to compute the average of a list (array) of numbers:
 avg=: +/ % #
# counts the number of items in the array. +/ sums the items of the
array. % divides the sum by the number of items"

You might also call it argument-free or something like that.
Without arguments?
Silent?

I like referring to it as pointless - and I take it more in a positive
way as funny - I like tacit even if I am not very good at it.


2009/11/7 James Foit <jimfoit@...>:

>
> I was googling 'tacit programming', found this:
> http://en.wikipedia.org/wiki/Tacit_programming
> And noticed near the top of the page this line:
> "Outside of the APL and J communities, tacit programming is referred to as point-free style[1], or more pithily as pointless programming."
>
> Someone with a wiki account may want to remove the final clause.  Innuendo like that can destroy all that u guys work for.
>
>> Date: Sat, 7 Nov 2009 11:08:57 +0800
>> From: bbill.lam@...
>> To: programming@...
>> Subject: Re: [Jprogramming] Stacked Bar Chart
>>
>> On Fri, 06 Nov 2009, Thomas Costigliola wrote:
>> > The given plot was produced with R; it has an incredibly flexible
>> > plotting package.
>>
>> Not exactly an answer.  There are plot packages (eg. goffice) for gtk+
>> (untested).
>>
>> --
>> regards,
>> ====================================================
>> GPG key 1024D/4434BAB3 2008-08-24
>> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



--
Björn Helgason, Verkfræðingur
Fugl&Fiskur ehf,
Þerneyjarsundi 23, Hraunborgum
Po Box 127,801 Selfoss ,
t-póst: gosinn@...
gsm: +3546985532
Landslags og skrúðgarðagerð, gröfuþjónusta
http://groups.google.com/group/J-Programming


Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans

góður kennari getur stigið á tær án þess að glansinn fari af skónum
          /|_      .-----------------------------------.
         ,'  .\  /  | Með léttri lund verður        |
     ,--'    _,'   | Dagurinn í dag                     |
    /       /       | Enn betri en gærdagurinn  |
   (   -.  |        `-----------------------------------'
   |     ) |         (\_ _/)
  (`-.  '--.)       (='.'=)   ♖♘♗♕♔♙
   `. )----'        (")_(") ☃☠
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Innuendo

by James Foit :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


People see truth in humor.  And people use humor to crush their competition.

> Date: Sat, 7 Nov 2009 09:46:29 +0000
> From: gosinn@...
> To: programming@...
> Subject: Re: [Jprogramming] Stacked Bar Chart
>
> It is actually more just funny comment.
>
> From the same page
>
> "APL (family)
> In J one can see the same sort of point-free code in a function
> designed to compute the average of a list (array) of numbers:
>  avg=: +/ % #
> # counts the number of items in the array. +/ sums the items of the
> array. % divides the sum by the number of items"
>
> You might also call it argument-free or something like that.
> Without arguments?
> Silent?
>
> I like referring to it as pointless - and I take it more in a positive
> way as funny - I like tacit even if I am not very good at it.
>
>
> 2009/11/7 James Foit <jimfoit@...>:
> >
> > I was googling 'tacit programming', found this:
> > http://en.wikipedia.org/wiki/Tacit_programming
> > And noticed near the top of the page this line:
> > "Outside of the APL and J communities, tacit programming is referred to as point-free style[1], or more pithily as pointless programming."
> >
> > Someone with a wiki account may want to remove the final clause.  Innuendo like that can destroy all that u guys work for.
> >
> >> Date: Sat, 7 Nov 2009 11:08:57 +0800
> >> From: bbill.lam@...
> >> To: programming@...
> >> Subject: Re: [Jprogramming] Stacked Bar Chart
> >>
> >> On Fri, 06 Nov 2009, Thomas Costigliola wrote:
> >> > The given plot was produced with R; it has an incredibly flexible
> >> > plotting package.
> >>
> >> Not exactly an answer.  There are plot packages (eg. goffice) for gtk+
> >> (untested).
> >>
> >> --
> >> regards,
> >> ====================================================
> >> GPG key 1024D/4434BAB3 2008-08-24
> >> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
>
>
> --
> Björn Helgason, Verkfræðingur
> Fugl&Fiskur ehf,
> Þerneyjarsundi 23, Hraunborgum
> Po Box 127,801 Selfoss ,
> t-póst: gosinn@...
> gsm: +3546985532
> Landslags og skrúðgarðagerð, gröfuþjónusta
> http://groups.google.com/group/J-Programming
>
>
> Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans
>
> góður kennari getur stigið á tær án þess að glansinn fari af skónum
>           /|_      .-----------------------------------.
>          ,'  .\  /  | Með léttri lund verður        |
>      ,--'    _,'   | Dagurinn í dag                     |
>     /       /       | Enn betri en gærdagurinn  |
>    (   -.  |        `-----------------------------------'
>    |     ) |         (\_ _/)
>   (`-.  '--.)       (='.'=)   ♖♘♗♕♔♙
>    `. )----'        (")_(") ☃☠
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
     
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Innuendo

by bill lam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, 07 Nov 2009, James Foit wrote:
>
> People see truth in humor.  And people use humor to crush their competition.
 
I didn't feel being mocked, albeit the term 'pointless' may be an
oxymoron in that context.  Nice word play.

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> From: Thomas Costigliola
>
> I would like to create a chart like the one in the link below. It is a
> stacked bar chart with no space between the bars. Plot doesn't seem to
> allow negative values in stacked bar charts. Is there any work around
> for this? There would also need to be a way to draw the bars next to
> each other as in a histogram.
>
> The given plot was produced with R; it has an incredibly flexible
> plotting package.
>
> http://www.jsoftware.com/jwiki/ThomasCostigliola

The gap between bars can be adjusted using the "barwidth" option.
"http://www.jsoftware.com/jwiki/Plot/Options"

   'bar;barwidth 1;' plot 3 9 8 _3 9 _7

However I don't think you're going to to get the output you're after using existing plot types and options in J.
I see two main avenues of choices:

0. Use the stats/r/rserve addon (interface to R) to create your chart from J data using R.
Below is a very basic example of how you could create an R chart as a PDF from J.

   load 'stats/r/rserve task'
   Rcmd 'x<- seq(-10,10,length=50)'
   Rcmd 'y<- x'
   Rcmd 'foo<- function(x,y){r<-sqrt(x^2+y^2);10*sin(r)/r}'
   Rcmd 'z<- outer(x , y , foo)'
   Rcmd 'pdf(file="c:\\users\\rsherloc\\documents\\j602-user\\temp\\RicRplot001.pdf")'
   Rcmd 'persp(x,y,z,theta=30,phi=30,expand=0.5,xlab="X",ylab="Y",zlab="Z")'
   Rcmd 'dev.off()'
   launch jpath '~temp/RicRplot001.pdf'

For your purposes you'd want to send the raw data from J to R for plotting rather than create in R as in the above example (otherwise you might as well just do the whole thing in R!?!

1. Create a new custom chart type
There was a good thread on modifying and combining existing chart types in the forums about a year ago where Oleg gave an example of how to write a custom plot type.
"http://www.jsoftware.com/pipermail/programming/2008-November/013009.html"

I've got a draft of a wiki page summarizing the thread somewhere that I must get around to adding to the wiki.



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by Thomas Costigliola-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you for the information. Option 1 led me to great example code
so I went ahead and added a new chart type. There had to be some
changes to other functions within the jzplot class so I updated the
whole class. I attempted to make a subclass but was unsuccessful. All
the results can be found here:

 http://www.jsoftware.com/jwiki/Improved%20Stacked%20Bar%20Graph

On Sun, Nov 8, 2009 at 5:08 AM, Sherlock, Ric <R.G.Sherlock@...> wrote:

>> From: Thomas Costigliola
>>
>> I would like to create a chart like the one in the link below. It is a
>> stacked bar chart with no space between the bars. Plot doesn't seem to
>> allow negative values in stacked bar charts. Is there any work around
>> for this? There would also need to be a way to draw the bars next to
>> each other as in a histogram.
>>
>> The given plot was produced with R; it has an incredibly flexible
>> plotting package.
>>
>> http://www.jsoftware.com/jwiki/ThomasCostigliola
>
> The gap between bars can be adjusted using the "barwidth" option.
> "http://www.jsoftware.com/jwiki/Plot/Options"
>
>   'bar;barwidth 1;' plot 3 9 8 _3 9 _7
>
> However I don't think you're going to to get the output you're after using existing plot types and options in J.
> I see two main avenues of choices:
>
> 0. Use the stats/r/rserve addon (interface to R) to create your chart from J data using R.
> Below is a very basic example of how you could create an R chart as a PDF from J.
>
>   load 'stats/r/rserve task'
>   Rcmd 'x<- seq(-10,10,length=50)'
>   Rcmd 'y<- x'
>   Rcmd 'foo<- function(x,y){r<-sqrt(x^2+y^2);10*sin(r)/r}'
>   Rcmd 'z<- outer(x , y , foo)'
>   Rcmd 'pdf(file="c:\\users\\rsherloc\\documents\\j602-user\\temp\\RicRplot001.pdf")'
>   Rcmd 'persp(x,y,z,theta=30,phi=30,expand=0.5,xlab="X",ylab="Y",zlab="Z")'
>   Rcmd 'dev.off()'
>   launch jpath '~temp/RicRplot001.pdf'
>
> For your purposes you'd want to send the raw data from J to R for plotting rather than create in R as in the above example (otherwise you might as well just do the whole thing in R!?!
>
> 1. Create a new custom chart type
> There was a good thread on modifying and combining existing chart types in the forums about a year ago where Oleg gave an example of how to write a custom plot type.
> "http://www.jsoftware.com/pipermail/programming/2008-November/013009.html"
>
> I've got a draft of a wiki page summarizing the thread somewhere that I must get around to adding to the wiki.
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That's great Thomas.

Some comments:
Do you need to special case when edgecolor is _1 ? Could you just use an edgesize of 0 to get the same result? That simplifies your makedrawbar verb.

Note that you can define an object in the class jzplot from a script other than jzplot.ijs. So you can get away with quite a few less (or no) edits to jzplot.ijs by using Oleg's typereg verb to register your new plot type.  The script below should work without any changes to jzplot.ijs.

However I think your generalization of getdatarange and addition of a new plot type category (SumHalfYTypes) to jzplot that is special-cased by getmin and getmax might be a good addition to jzplot.
Maybe typereg or similar should be added to the base library (jzplot.ijs ?) too?

Regards,
Ric

NB.==========Custom Plot script ===============================

require 'plot'

coclass 'pzplot'
coinsert 'jzplot'

NB.*typereg v register plot type (framework)
typereg=: 4 : 0
  ('plot_',y,'_jzplot_')=: ('plot_',y,'_',(>coname''),'_')~ f.
  for_i. x do.
    ((>i),'_jzplot_')=: (((>i),'_jzplot_')~ -. <y),<y
  end.
  PlotTypes_jzplot_=: ~. PlotTypes2d_jzplot_,PlotTypes3d_jzplot_

  empty''
)

plot_sbarn=: 3 : 0
'x y'=. 2 {. y { Data
dat=. citemize y
pos=. makestackbarn dat
pos makedrawbar dat
)

makedrawbar_jzplot_=: 4 : 0
pos=. x
dat=. y
'r c'=. $dat
if. r=1 do.
  drawrect iDATA;EDGECOLOR;EDGESIZE;(ITEMCOLOR {~ 0 >, dat);pos
else.
  clr=. r $ ITEMCOLOR
  pos=. (-c) ,\ pos
  for_p. pos do.
   drawrect iDATA;EDGECOLOR;EDGESIZE;(p_index{clr);_4 ]\ p
  end.
end.
)

makestackbarn_jzplot_=: 3 : 0
'r c'=. $y
wid=. BARWIDTH
w=. Gw * wid % c
t=. Gw * -: (-.wid) % c
o=. |YMin % YMax-YMin
uh=. (1-o) * Gh
lh=. o * Gh
m=. 0&<:y
y=. m (* ,: -.@[*]) y
y=. +/\."2 y
h=. (uh,lh) * y % YMax,|YMin
h=. (-.m)} h
y=. Gy + lh + ,h
x=. Gx + ($y) $ t + Gw * }: int01 c
x,.y,.(x+w),.y-,h
)

(;:'PlotTypes2d') typereg 'sbarn'


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

   dat=: |:(+0.5-[:?0$~#)^:(<100) 0 _4 4 0
   pd 'new'
   pd 'type sbarn; edgesize 0; barwidth 1;xtic 10 2'
   NB. next 2 lines in lieu of getmin, getmax edits to jzplot.ijs
   minmax=. (<./@:({:"1) , >./@:({."1)) (0&< +//. ])"1 |:dat
   pd 'yrange ',": _2.5 2.5 <.@:+ minmax
   pd  dat
   pd 'type line;color 0 0 0; pensize 2;xtic 10 2'
   pd +/dat
   pd 'show'    )

NB.=========================================

> From: Thomas Costigliola
>
> Thank you for the information. Option 1 led me to great example code
> so I went ahead and added a new chart type. There had to be some
> changes to other functions within the jzplot class so I updated the
> whole class. I attempted to make a subclass but was unsuccessful. All
> the results can be found here:
>
>  http://www.jsoftware.com/jwiki/Improved%20Stacked%20Bar%20Graph
>
> On Sun, Nov 8, 2009 at 5:08 AM, Sherlock, Ric wrote:
> >> From: Thomas Costigliola
> >>
> >> I would like to create a chart like the one in the link below. It is
> a
> >> stacked bar chart with no space between the bars. Plot doesn't seem
> to
> >> allow negative values in stacked bar charts. Is there any work
> around
> >> for this? There would also need to be a way to draw the bars next to
> >> each other as in a histogram.
> >>
> >> The given plot was produced with R; it has an incredibly flexible
> >> plotting package.
> >>
> >> http://www.jsoftware.com/jwiki/ThomasCostigliola
> >
> > The gap between bars can be adjusted using the "barwidth" option.
> > "http://www.jsoftware.com/jwiki/Plot/Options"
> >
> >   'bar;barwidth 1;' plot 3 9 8 _3 9 _7
> >
> > However I don't think you're going to to get the output you're after
> using existing plot types and options in J.
> > I see two main avenues of choices:
> >
> > 0. Use the stats/r/rserve addon (interface to R) to create your chart
> from J data using R.
> > Below is a very basic example of how you could create an R chart as a
> PDF from J.
> >
> >   load 'stats/r/rserve task'
> >   Rcmd 'x<- seq(-10,10,length=50)'
> >   Rcmd 'y<- x'
> >   Rcmd 'foo<- function(x,y){r<-sqrt(x^2+y^2);10*sin(r)/r}'
> >   Rcmd 'z<- outer(x , y , foo)'
> >   Rcmd 'pdf(file="c:\\users\\rsherloc\\documents\\j602-
> user\\temp\\RicRplot001.pdf")'
> >   Rcmd
> 'persp(x,y,z,theta=30,phi=30,expand=0.5,xlab="X",ylab="Y",zlab="Z")'
> >   Rcmd 'dev.off()'
> >   launch jpath '~temp/RicRplot001.pdf'
> >
> > For your purposes you'd want to send the raw data from J to R for
> plotting rather than create in R as in the above example (otherwise you
> might as well just do the whole thing in R!?!
> >
> > 1. Create a new custom chart type
> > There was a good thread on modifying and combining existing chart
> types in the forums about a year ago where Oleg gave an example of how
> to write a custom plot type.
> > "http://www.jsoftware.com/pipermail/programming/2008-
> November/013009.html"
> >
> > I've got a draft of a wiki page summarizing the thread somewhere that
> I must get around to adding to the wiki.
> >
> >
> >
> > ---------------------------------------------------------------------
> -
> > For information about J forums see
> http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> From: Sherlock, Ric
>
> Some comments:
> Do you need to special case when edgecolor is _1 ? Could you just use
> an edgesize of 0 to get the same result? That simplifies your
> makedrawbar verb.

Actually I see now that without that special case handling it is exactly the same as the existing makedrawbar_jzplot_ verb and could therefore be left out of the script altogether:

NB.==========Custom Stacked Bar script==============================
require 'plot'

coclass 'pzplot'
coinsert 'jzplot'

NB.*typereg v register plot type (framework)
typereg=: 4 : 0
  ('plot_',y,'_jzplot_')=: ('plot_',y,'_',(>coname''),'_')~ f.
  for_i. x do.
    ((>i),'_jzplot_')=: (((>i),'_jzplot_')~ -. <y),<y
  end.
  PlotTypes_jzplot_=: ~. PlotTypes2d_jzplot_,PlotTypes3d_jzplot_

  empty''
)

plot_sbarn=: 3 : 0
'x y'=. 2 {. y { Data
dat=. citemize y
pos=. makestackbarn dat
pos makedrawbar dat
)

makestackbarn_jzplot_=: 3 : 0
'r c'=. $y
wid=. BARWIDTH
w=. Gw * wid % c
t=. Gw * -: (-.wid) % c
o=. |YMin % YMax-YMin
uh=. (1-o) * Gh
lh=. o * Gh
m=. 0&<:y
y=. m (* ,: -.@[*]) y
y=. +/\."2 y
h=. (uh,lh) * y % YMax,|YMin
h=. (-.m)} h
y=. Gy + lh + ,h
x=. Gx + ($y) $ t + Gw * }: int01 c
x,.y,.(x+w),.y-,h
)

(;:'PlotTypes2d') typereg 'sbarn'

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

   dat=: |:(+0.5-[:?0$~#)^:(<100) 0 _4 4 0
   pd 'new'
   pd 'type sbarn; edgesize 0; barwidth 1;xtic 10 2'
   NB. next 2 lines in lieu of getmin, getmax edits to jzplot.ijs
   minmax=. ({.@:<./ , {:@:>./) (0&< +//. ])@/:~"1 |:dat
   pd 'yrange ',": _2.5 2.5 <.@:+ minmax
   pd  dat
   pd 'type line;color 0 0 0; pensize 2;xtic 10 2'
   pd +/dat
   pd 'show'    
)
NB. ==========================================

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Parent Message unknown Re: Stacked Bar Chart

by Oleg Kobchenko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If signed bars is a superset of regular bars, should it an enhancement to
existing bar type, rather than a new type?



On Nov 10, 2009, at 11:33 AM, Thomas Costigliola <tcostigl@...> wrote:

Thank you for the information. Option 1 led me to great example code
so I went ahead and added a new chart type. There had to be some
changes to other functions within the jzplot class so I updated the
whole class. I attempted to make a subclass but was unsuccessful. All
the results can be found here:

http://www.jsoftware.com/jwiki/Improved%20Stacked%20Bar%20Graph

On Sun, Nov 8, 2009 at 5:08 AM, Sherlock, Ric <R.G.Sherlock@...> wrote:
From: Thomas Costigliola

I would like to create a chart like the one in the link below. It is a
stacked bar chart with no space between the bars. Plot doesn't seem to
allow negative values in stacked bar charts. Is there any work around
for this? There would also need to be a way to draw the bars next to
each other as in a histogram.

The given plot was produced with R; it has an incredibly flexible
plotting package.

http://www.jsoftware.com/jwiki/ThomasCostigliola

The gap between bars can be adjusted using the "barwidth" option.
"http://www.jsoftware.com/jwiki/Plot/Options"

  'bar;barwidth 1;' plot 3 9 8 _3 9 _7

However I don't think you're going to to get the output you're after using existing plot types and options in J.
I see two main avenues of choices:

0. Use the stats/r/rserve addon (interface to R) to create your chart from J data using R.
Below is a very basic example of how you could create an R chart as a PDF from J.

  load 'stats/r/rserve task'
  Rcmd 'x<- seq(-10,10,length=50)'
  Rcmd 'y<- x'
  Rcmd 'foo<- function(x,y){r<-sqrt(x^2+y^2);10*sin(r)/r}'
  Rcmd 'z<- outer(x , y , foo)'
  Rcmd 'pdf(file="c:\\users\\rsherloc\\documents\\j602-user\\temp\\RicRplot001.pdf")'
  Rcmd 'persp(x,y,z,theta=30,phi=30,expand=0.5,xlab="X",ylab="Y",zlab="Z")'
  Rcmd 'dev.off()'
  launch jpath '~temp/RicRplot001.pdf'

For your purposes you'd want to send the raw data from J to R for plotting rather than create in R as in the above example (otherwise you might as well just do the whole thing in R!?!

1. Create a new custom chart type
There was a good thread on modifying and combining existing chart types in the forums about a year ago where Oleg gave an example of how to write a custom plot type.
"http://www.jsoftware.com/pipermail/programming/2008-November/013009.html"

I've got a draft of a wiki page summarizing the thread somewhere that I must get around to adding to the wiki.



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm



     
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Parent Message unknown Re: Stacked Bar Chart

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Sent from my Windows® phone.

-----Original Message-----
From: Oleg Kobchenko <olegykj@...>
Sent: Wednesday, 11 November 2009 21:01
To: Programming forum <programming@...>
Subject: Re: [Jprogramming] Stacked Bar Chart


If signed bars is a superset of regular bars, should it an enhancement to
existing bar type, rather than a new type?



On Nov 10, 2009, at 11:33 AM, Thomas Costigliola <tcostigl@...> wrote:

Thank you for the information. Option 1 led me to great example code
so I went ahead and added a new chart type. There had to be some
changes to other functions within the jzplot class so I updated the
whole class. I attempted to make a subclass but was unsuccessful. All
the results can be found here:

http://www.jsoftware.com/jwiki/Improved%20Stacked%20Bar%20Graph

On Sun, Nov 8, 2009 at 5:08 AM, Sherlock, Ric <R.G.Sherlock@...> wrote:
From: Thomas Costigliola

I would like to create a chart like the one in the link below. It is a
stacked bar chart with no space between the bars. Plot doesn't seem to
allow negative values in stacked bar charts. Is there any work around
for this? There would also need to be a way to draw the bars next to
each other as in a histogram.

The given plot was produced with R; it has an incredibly flexible
plotting package.

http://www.jsoftware.com/jwiki/ThomasCostigliola

The gap between bars can be adjusted using the "barwidth" option.
"http://www.jsoftware.com/jwiki/Plot/Options"

  'bar;barwidth 1;' plot 3 9 8 _3 9 _7

However I don't think you're going to to get the output you're after using existing plot types and options in J.
I see two main avenues of choices:

0. Use the stats/r/rserve addon (interface to R) to create your chart from J data using R.
Below is a very basic example of how you could create an R chart as a PDF from J.

  load 'stats/r/rserve task'
  Rcmd 'x<- seq(-10,10,length=50)'
  Rcmd 'y<- x'
  Rcmd 'foo<- function(x,y){r<-sqrt(x^2+y^2);10*sin(r)/r}'
  Rcmd 'z<- outer(x , y , foo)'
  Rcmd 'pdf(file="c:\\users\\rsherloc\\documents\\j602-user\\temp\\RicRplot001.pdf")'
  Rcmd 'persp(x,y,z,theta=30,phi=30,expand=0.5,xlab="X",ylab="Y",zlab="Z")'
  Rcmd 'dev.off()'
  launch jpath '~temp/RicRplot001.pdf'

For your purposes you'd want to send the raw data from J to R for plotting rather than create in R as in the above example (otherwise you might as well just do the whole thing in R!?!

1. Create a new custom chart type
There was a good thread on modifying and combining existing chart types in the forums about a year ago where Oleg gave an example of how to write a custom plot type.
"http://www.jsoftware.com/pipermail/programming/2008-November/013009.html"

I've got a draft of a wiki page summarizing the thread somewhere that I must get around to adding to the wiki.



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Parent Message unknown Re: Stacked Bar Chart

by Oleg Kobchenko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We sure all acknowledged that fact :)


On Nov 11, 2009, at 12:16 AM, "Sherlock, Ric" <R.G.Sherlock@...> wrote:



Sent from my Windows® phone.

-----Original Message-----
From: Oleg Kobchenko <olegykj@...>
Sent: Wednesday, 11 November 2009 21:01
To: Programming forum <programming@...>
Subject: Re: [Jprogramming] Stacked Bar Chart


If signed bars is a superset of regular bars, should it an enhancement to
existing bar type, rather than a new type?



On Nov 10, 2009, at 11:33 AM, Thomas Costigliola <tcostigl@...> wrote:

Thank you for the information. Option 1 led me to great example code
so I went ahead and added a new chart type. There had to be some
changes to other functions within the jzplot class so I updated the
whole class. I attempted to make a subclass but was unsuccessful. All
the results can be found here:

http://www.jsoftware.com/jwiki/Improved%20Stacked%20Bar%20Graph

On Sun, Nov 8, 2009 at 5:08 AM, Sherlock, Ric <R.G.Sherlock@...> wrote:
From: Thomas Costigliola

I would like to create a chart like the one in the link below. It is a
stacked bar chart with no space between the bars. Plot doesn't seem to
allow negative values in stacked bar charts. Is there any work around
for this? There would also need to be a way to draw the bars next to
each other as in a histogram.

The given plot was produced with R; it has an incredibly flexible
plotting package.

http://www.jsoftware.com/jwiki/ThomasCostigliola

The gap between bars can be adjusted using the "barwidth" option.
"http://www.jsoftware.com/jwiki/Plot/Options"

 'bar;barwidth 1;' plot 3 9 8 _3 9 _7

However I don't think you're going to to get the output you're after using existing plot types and options in J.
I see two main avenues of choices:

0. Use the stats/r/rserve addon (interface to R) to create your chart from J data using R.
Below is a very basic example of how you could create an R chart as a PDF from J.

 load 'stats/r/rserve task'
 Rcmd 'x<- seq(-10,10,length=50)'
 Rcmd 'y<- x'
 Rcmd 'foo<- function(x,y){r<-sqrt(x^2+y^2);10*sin(r)/r}'
 Rcmd 'z<- outer(x , y , foo)'
 Rcmd 'pdf(file="c:\\users\\rsherloc\\documents\\j602-user\\temp\\RicRplot001.pdf")'
 Rcmd 'persp(x,y,z,theta=30,phi=30,expand=0.5,xlab="X",ylab="Y",zlab="Z")'
 Rcmd 'dev.off()'
 launch jpath '~temp/RicRplot001.pdf'

For your purposes you'd want to send the raw data from J to R for plotting rather than create in R as in the above example (otherwise you might as well just do the whole thing in R!?!

1. Create a new custom chart type
There was a good thread on modifying and combining existing chart types in the forums about a year ago where Oleg gave an example of how to write a custom plot type.
"http://www.jsoftware.com/pipermail/programming/2008-November/013009.html"

I've got a draft of a wiki page summarizing the thread somewhere that I must get around to adding to the wiki.



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm



     
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Parent Message unknown Re: Stacked Bar Chart

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I was thinking along similar lines . The current stacked bar disallows negative values (gives error). Thomas' version should produce the same results as the current one for datasets without negatives. So with his suggested  changes to getmin and getmax and replacing the current makestackbar with makestackbarn we would just have a more functional sbar type. Any downsides?

Sent from my Windows® phone.

-----Original Message-----
From: Oleg Kobchenko <olegykj@...>
Sent: Wednesday, 11 November 2009 21:01
To: Programming forum <programming@...>
Subject: Re: [Jprogramming] Stacked Bar Chart


If signed bars is a superset of regular bars, should it an enhancement to
existing bar type, rather than a new type?



On Nov 10, 2009, at 11:33 AM, Thomas Costigliola <tcostigl@...> wrote:

Thank you for the information. Option 1 led me to great example code
so I went ahead and added a new chart type. There had to be some
changes to other functions within the jzplot class so I updated the
whole class. I attempted to make a subclass but was unsuccessful. All
the results can be found here:

http://www.jsoftware.com/jwiki/Improved%20Stacked%20Bar%20Graph

On Sun, Nov 8, 2009 at 5:08 AM, Sherlock, Ric <R.G.Sherlock@...> wrote:
From: Thomas Costigliola

I would like to create a chart like the one in the link below. It is a
stacked bar chart with no space between the bars. Plot doesn't seem to
allow negative values in stacked bar charts. Is there any work around
for this? There would also need to be a way to draw the bars next to
each other as in a histogram.

The given plot was produced with R; it has an incredibly flexible
plotting package.

http://www.jsoftware.com/jwiki/ThomasCostigliola

The gap between bars can be adjusted using the "barwidth" option.
"http://www.jsoftware.com/jwiki/Plot/Options"

  'bar;barwidth 1;' plot 3 9 8 _3 9 _7

However I don't think you're going to to get the output you're after using existing plot types and options in J.
I see two main avenues of choices:

0. Use the stats/r/rserve addon (interface to R) to create your chart from J data using R.
Below is a very basic example of how you could create an R chart as a PDF from J.

  load 'stats/r/rserve task'
  Rcmd 'x<- seq(-10,10,length=50)'
  Rcmd 'y<- x'
  Rcmd 'foo<- function(x,y){r<-sqrt(x^2+y^2);10*sin(r)/r}'
  Rcmd 'z<- outer(x , y , foo)'
  Rcmd 'pdf(file="c:\\users\\rsherloc\\documents\\j602-user\\temp\\RicRplot001.pdf")'
  Rcmd 'persp(x,y,z,theta=30,phi=30,expand=0.5,xlab="X",ylab="Y",zlab="Z")'
  Rcmd 'dev.off()'
  launch jpath '~temp/RicRplot001.pdf'

For your purposes you'd want to send the raw data from J to R for plotting rather than create in R as in the above example (otherwise you might as well just do the whole thing in R!?!

1. Create a new custom chart type
There was a good thread on modifying and combining existing chart types in the forums about a year ago where Oleg gave an example of how to write a custom plot type.
"http://www.jsoftware.com/pipermail/programming/2008-November/013009.html"

I've got a draft of a wiki page summarizing the thread somewhere that I must get around to adding to the wiki.



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Parent Message unknown Re: Stacked Bar Chart

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry 'bout that. Have turned off the signature so next time I stuff up it will just be an empty message. ;-)


-----Original Message-----
From: Oleg Kobchenko <olegykj@...>
Sent: Wednesday, 11 November 2009 21:23
To: Programming forum <programming@...>
Subject: Re: [Jprogramming] Stacked Bar Chart


We sure all acknowledged that fact :)


On Nov 11, 2009, at 12:16 AM, "Sherlock, Ric" <R.G.Sherlock@...> wrote:



Sent from my Windows® phone.

-----Original Message-----
From: Oleg Kobchenko <olegykj@...>
Sent: Wednesday, 11 November 2009 21:01
To: Programming forum <programming@...>
Subject: Re: [Jprogramming] Stacked Bar Chart


If signed bars is a superset of regular bars, should it an enhancement to
existing bar type, rather than a new type?



On Nov 10, 2009, at 11:33 AM, Thomas Costigliola <tcostigl@...> wrote:

Thank you for the information. Option 1 led me to great example code
so I went ahead and added a new chart type. There had to be some
changes to other functions within the jzplot class so I updated the
whole class. I attempted to make a subclass but was unsuccessful. All
the results can be found here:

http://www.jsoftware.com/jwiki/Improved%20Stacked%20Bar%20Graph

On Sun, Nov 8, 2009 at 5:08 AM, Sherlock, Ric <R.G.Sherlock@...> wrote:
From: Thomas Costigliola

I would like to create a chart like the one in the link below. It is a
stacked bar chart with no space between the bars. Plot doesn't seem to
allow negative values in stacked bar charts. Is there any work around
for this? There would also need to be a way to draw the bars next to
each other as in a histogram.

The given plot was produced with R; it has an incredibly flexible
plotting package.

http://www.jsoftware.com/jwiki/ThomasCostigliola

The gap between bars can be adjusted using the "barwidth" option.
"http://www.jsoftware.com/jwiki/Plot/Options"

 'bar;barwidth 1;' plot 3 9 8 _3 9 _7

However I don't think you're going to to get the output you're after using existing plot types and options in J.
I see two main avenues of choices:

0. Use the stats/r/rserve addon (interface to R) to create your chart from J data using R.
Below is a very basic example of how you could create an R chart as a PDF from J.

 load 'stats/r/rserve task'
 Rcmd 'x<- seq(-10,10,length=50)'
 Rcmd 'y<- x'
 Rcmd 'foo<- function(x,y){r<-sqrt(x^2+y^2);10*sin(r)/r}'
 Rcmd 'z<- outer(x , y , foo)'
 Rcmd 'pdf(file="c:\\users\\rsherloc\\documents\\j602-user\\temp\\RicRplot001.pdf")'
 Rcmd 'persp(x,y,z,theta=30,phi=30,expand=0.5,xlab="X",ylab="Y",zlab="Z")'
 Rcmd 'dev.off()'
 launch jpath '~temp/RicRplot001.pdf'

For your purposes you'd want to send the raw data from J to R for plotting rather than create in R as in the above example (otherwise you might as well just do the whole thing in R!?!

1. Create a new custom chart type
There was a good thread on modifying and combining existing chart types in the forums about a year ago where Oleg gave an example of how to write a custom plot type.
"http://www.jsoftware.com/pipermail/programming/2008-November/013009.html"

I've got a draft of a wiki page summarizing the thread somewhere that I must get around to adding to the wiki.



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by Thomas Costigliola-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, EDGESIZE=0 produces the correct output so makedrawbar does not
need to be modified.

Thanks for the script, that was my idea but I didn't think I had to
explicitly define the verbs in the jzplot locale by adding the
_jzplot_ becuase of the coinsert statement. Why is this necessary?

On Tue, Nov 10, 2009 at 8:19 PM, Sherlock, Ric
<R.G.Sherlock@...> wrote:

>> From: Sherlock, Ric
>>
>> Some comments:
>> Do you need to special case when edgecolor is _1 ? Could you just use
>> an edgesize of 0 to get the same result? That simplifies your
>> makedrawbar verb.
>
> Actually I see now that without that special case handling it is exactly the same as the existing makedrawbar_jzplot_ verb and could therefore be left out of the script altogether:
>
> NB.==========Custom Stacked Bar script==============================
> require 'plot'
>
> coclass 'pzplot'
> coinsert 'jzplot'
>
> NB.*typereg v register plot type (framework)
> typereg=: 4 : 0
>  ('plot_',y,'_jzplot_')=: ('plot_',y,'_',(>coname''),'_')~ f.
>  for_i. x do.
>    ((>i),'_jzplot_')=: (((>i),'_jzplot_')~ -. <y),<y
>  end.
>  PlotTypes_jzplot_=: ~. PlotTypes2d_jzplot_,PlotTypes3d_jzplot_
>
>  empty''
> )
>
> plot_sbarn=: 3 : 0
> 'x y'=. 2 {. y { Data
> dat=. citemize y
> pos=. makestackbarn dat
> pos makedrawbar dat
> )
>
> makestackbarn_jzplot_=: 3 : 0
> 'r c'=. $y
> wid=. BARWIDTH
> w=. Gw * wid % c
> t=. Gw * -: (-.wid) % c
> o=. |YMin % YMax-YMin
> uh=. (1-o) * Gh
> lh=. o * Gh
> m=. 0&<:y
> y=. m (* ,: -.@[*]) y
> y=. +/\."2 y
> h=. (uh,lh) * y % YMax,|YMin
> h=. (-.m)} h
> y=. Gy + lh + ,h
> x=. Gx + ($y) $ t + Gw * }: int01 c
> x,.y,.(x+w),.y-,h
> )
>
> (;:'PlotTypes2d') typereg 'sbarn'
>
> Note 'usage'
>   'sbarn' plot (],:|.)@:(,|.@:-) i.5
>
>   dat=: |:(+0.5-[:?0$~#)^:(<100) 0 _4 4 0
>   pd 'new'
>   pd 'type sbarn; edgesize 0; barwidth 1;xtic 10 2'
>   NB. next 2 lines in lieu of getmin, getmax edits to jzplot.ijs
>   minmax=. ({.@:<./ , {:@:>./) (0&< +//. ])@/:~"1 |:dat
>   pd 'yrange ',": _2.5 2.5 <.@:+ minmax
>   pd  dat
>   pd 'type line;color 0 0 0; pensize 2;xtic 10 2'
>   pd +/dat
>   pd 'show'
> )
> NB. ==========================================
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by Thomas Costigliola-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Replacing the existing functionality would be ideal. There is
currently one caveat however. I defined the "sbarn" type to be
treating as a line graph when drawing the x-axis labels. The bar graph
types always draw every label by default. I prefer it this way but
some may not. In that case I would suggest treating the new stacked
bar graph as a bar graph for drawing labels and updating the area
graph in a similar way.

On Wed, Nov 11, 2009 at 3:36 AM, Sherlock, Ric
<R.G.Sherlock@...> wrote:

> I was thinking along similar lines . The current stacked bar disallows negative values (gives error). Thomas' version should produce the same results as the current one for datasets without negatives. So with his suggested  changes to getmin and getmax and replacing the current makestackbar with makestackbarn we would just have a more functional sbar type. Any downsides?
>
> Sent from my Windows® phone.
>
> -----Original Message-----
> From: Oleg Kobchenko <olegykj@...>
> Sent: Wednesday, 11 November 2009 21:01
> To: Programming forum <programming@...>
> Subject: Re: [Jprogramming] Stacked Bar Chart
>
>
> If signed bars is a superset of regular bars, should it an enhancement to
> existing bar type, rather than a new type?
>
>
>
> On Nov 10, 2009, at 11:33 AM, Thomas Costigliola <tcostigl@...> wrote:
>
> Thank you for the information. Option 1 led me to great example code
> so I went ahead and added a new chart type. There had to be some
> changes to other functions within the jzplot class so I updated the
> whole class. I attempted to make a subclass but was unsuccessful. All
> the results can be found here:
>
> http://www.jsoftware.com/jwiki/Improved%20Stacked%20Bar%20Graph
>
> On Sun, Nov 8, 2009 at 5:08 AM, Sherlock, Ric <R.G.Sherlock@...> wrote:
> From: Thomas Costigliola
>
> I would like to create a chart like the one in the link below. It is a
> stacked bar chart with no space between the bars. Plot doesn't seem to
> allow negative values in stacked bar charts. Is there any work around
> for this? There would also need to be a way to draw the bars next to
> each other as in a histogram.
>
> The given plot was produced with R; it has an incredibly flexible
> plotting package.
>
> http://www.jsoftware.com/jwiki/ThomasCostigliola
>
> The gap between bars can be adjusted using the "barwidth" option.
> "http://www.jsoftware.com/jwiki/Plot/Options"
>
>  'bar;barwidth 1;' plot 3 9 8 _3 9 _7
>
> However I don't think you're going to to get the output you're after using existing plot types and options in J.
> I see two main avenues of choices:
>
> 0. Use the stats/r/rserve addon (interface to R) to create your chart from J data using R.
> Below is a very basic example of how you could create an R chart as a PDF from J.
>
>  load 'stats/r/rserve task'
>  Rcmd 'x<- seq(-10,10,length=50)'
>  Rcmd 'y<- x'
>  Rcmd 'foo<- function(x,y){r<-sqrt(x^2+y^2);10*sin(r)/r}'
>  Rcmd 'z<- outer(x , y , foo)'
>  Rcmd 'pdf(file="c:\\users\\rsherloc\\documents\\j602-user\\temp\\RicRplot001.pdf")'
>  Rcmd 'persp(x,y,z,theta=30,phi=30,expand=0.5,xlab="X",ylab="Y",zlab="Z")'
>  Rcmd 'dev.off()'
>  launch jpath '~temp/RicRplot001.pdf'
>
> For your purposes you'd want to send the raw data from J to R for plotting rather than create in R as in the above example (otherwise you might as well just do the whole thing in R!?!
>
> 1. Create a new custom chart type
> There was a good thread on modifying and combining existing chart types in the forums about a year ago where Oleg gave an example of how to write a custom plot type.
> "http://www.jsoftware.com/pipermail/programming/2008-November/013009.html"
>
> I've got a draft of a wiki page summarizing the thread somewhere that I must get around to adding to the wiki.
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by bill lam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 11 Nov 2009, Thomas Costigliola wrote:
> Yes, EDGESIZE=0 produces the correct output so makedrawbar does not
> need to be modified.
>
> Thanks for the script, that was my idea but I didn't think I had to
> explicitly define the verbs in the jzplot locale by adding the
> _jzplot_ becuase of the coinsert statement. Why is this necessary?
>

I didn't try that script but I guess it tried to modify class jzplot
itself on-the-fly so that the source of jzplot can remained
un-altered.  Alternatively you can modify source code of jzplot in svn
repository.

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The coinsert statement puts the jzplot in the search path of the locale you use it in (pzplot in this case).
   copath 'pzplot'
+------+----+----+-+
|jzplot|jafm|jgl2|z|
+------+----+----+-+

That means if you invoke a word in pzplot and the word is not defined in pzplot it will look to see if it is defined in the other locales further up the path. However invoking a word from a locale further up the path of pzplot will not search "downstream".

In this case when you invoke plot from the base locale, the plot verb is found in the z locale
   copath 'base'
+-+
|z|
+-+
If you look at the definition of plot_z_ you will see that it is pretty much a cover verb for plot_jwplot_
   copath 'jwplot'
+------+----+----+-+
|jzplot|jafm|jgl2|z|
+------+----+----+-+

So most of the words are being invoked from the jwplot locale which will however look in the jzplot locale for words it doesn't find in jwplot.  The pzplot locale isn't in the path however and so won't get searched.
If you haven't done the Locales lab yet (Studio|Labs|Locales), I'd recommend it.
     

> From: Thomas Costigliola
>
> Yes, EDGESIZE=0 produces the correct output so makedrawbar does not
> need to be modified.
>
> Thanks for the script, that was my idea but I didn't think I had to
> explicitly define the verbs in the jzplot locale by adding the
> _jzplot_ becuase of the coinsert statement. Why is this necessary?
>
> On Tue, Nov 10, 2009 at 8:19 PM, Sherlock, Ric wrote:
> >> From: Sherlock, Ric
> >>
> >> Some comments:
> >> Do you need to special case when edgecolor is _1 ? Could you just
> use
> >> an edgesize of 0 to get the same result? That simplifies your
> >> makedrawbar verb.
> >
> > Actually I see now that without that special case handling it is
> exactly the same as the existing makedrawbar_jzplot_ verb and could
> therefore be left out of the script altogether:

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Stacked Bar Chart

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> From: Sherlock, Ric
>
> In this case when you invoke plot from the base locale, the plot verb
> is found in the z locale
>    copath 'base'
> +-+
> |z|
> +-+
> If you look at the definition of plot_z_ you will see that it is pretty
> much a cover verb for plot_jwplot_
>    copath 'jwplot'
> +------+----+----+-+
> |jzplot|jafm|jgl2|z|
> +------+----+----+-+
>
> So most of the words are being invoked from the jwplot locale which
> will however look in the jzplot locale for words it doesn't find in
> jwplot.  The pzplot locale isn't in the path however and so won't get
> searched.

However this does suggest another alternative to defining the verbs/nouns directly in the jzplot locale. We could insert the pzplot locale in the path of jwplot, above jzplot, so any names defined in pzplot would take precedence over definitions in jzplot.
NB.========== script skeleton ==================
require 'plot'
((<'pzplot'),copath 'jwplot') copath 'jwplot'

coclass 'pzplot'
coinsert 'jzplot'

PlotTypes2d=: PlotTypes2d ,<'sbarn'
PlotTypes=: ~. PlotTypes2d,PlotTypes3d

plot_sbarn=: 3 : 0
'x y'=. 2 {. y { Data
dat=. citemize y
pos=. makestackbarn dat
pos makedrawbar dat
)

makestackbarn=: 3 : 0
'r c'=. $y
NB ... etc
)
NB. ============================================

   copath 'jwplot'
+------+------+------+----+----+-+
|pzplot|pzplot|jzplot|jafm|jgl2|z|
+------+------+------+----+----+-+
   copath 'pzplot'
+------+----+----+-+
|jzplot|jafm|jgl2|z|
+------+----+----+-+
   names_pzplot_''
PlotTypes     PlotTypes2d   makestackbarn plot_sbarn    

I've tested this and it works.

I'd be interested in any discussion of the relative merits of this approach over (re)defining objects directly in the jzplot locale. The main thing I'd be worried about with this approach is that the inheritance tree could get messy and hard to sort out, especially for multiple custom types?

A simpler idea would be to just use the jwplot locale (currently empty) for all custom types, but that would limit the ability to make one custom type an extension of another?

Thoughts anyone?


> If you haven't done the Locales lab yet (Studio|Labs|Locales), I'd
> recommend it.
>
>
> > From: Thomas Costigliola
> >
> > Thanks for the script, that was my idea but I didn't think I had to
> > explicitly define the verbs in the jzplot locale by adding the
> > _jzplot_ becuase of the coinsert statement. Why is this necessary?
> >

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm