Try instead:
a=:173 121 99 61 52 48 38 37 28 26 25 22 14 12 6 5 5 5 5 2 1 1 1
pd 1 round 100&*(%+/) a
This causes an error because it doesn't handle zeros, and there are four
at the end.
But even if we remove them as such:
pd _4}. 1 round 100&*(%+/) a
We get 4%, 2%, 3%, in a decreasing sequence.
It is adjusting so that the sum is 100%. There is no way to do this if
you want to round and always preserve the order relations in your data
(consider a 1/3, 1/3, 1/3 pie chart).
However, you could round in a better way to at least prevent < from
switching to >, by rounding up only those numbers with the largest
fractional parts.
In jzplot.ijs, comment out the line "val=. 1 rounddist dat" in the
definition of getpiepercent. Now, replace it with the following:
val=: {:"1 /:~ 2 1{"1 (-&100+/<.dat) (}.,((+&(0 1 0)"1)@{.))
/:~((]-<.),"0 1<.,"0([EMAIL PROTECTED])) dat
I'm sure someone can find a better expression, but this seems to do the
trick. If the fractional parts are the same it rounds the larger number
up (if they are not equal). You could also want to weight the rounding
so that either larger or smaller numbers are rounded up more, rather
than basing it solely on the fractional parts. But short of this I
believe this is the best way to round if you want your sum to be 100%
(if not, just use "val=. 1 round dat").
Jordan
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Brian Schott
Sent: Tuesday, June 17, 2008 12:54 PM
To: Programming forum
Subject: Re: [Jprogramming] displaying percents in pd pie charts
pd |. 1 round 100&*(%+/)50+i. 20
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
-----Original Message-----
J Programmers,
In making pie charts with pd, the percentages are not displaying in
order. My input data is in decreasing order, and the relative sizes of
the wedges look correct. However, the percent labels are not in
decreasing order.
For example, if I run the following code:
load 'plot'
pd 'type pie'
pd 'piepercent 1'
pd |.50+i.20
pd 'show'
It displays clockwise decreasing wedges, but labeled with percents 6, 6,
5, 6, 5, 6, 5, ...
Anyone know of this problem or how I might fix it?
Jordan Tirrell
[EMAIL PROTECTED]
a.{~74++/\0,37,(}:,(<:&{:))@(],-&])3 _14
a.{~84+0,(((-&2)&{.),}.)(6*3>i.6)&+,~17,,~24
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm