what I'm really looking for is a way to display discrete datasets in bar-graph
form with an indication of the standard deviation of the dataset. I've got
some good looking results by (mis) using stacked bar display but now need to
account for some negative sets. It isn't a problem to make the set completely
negative.
Or can you suggest a different approach? Using a linepoint plot with error
bars is ok, but a bar graph display looks so much better.
Thanks,
Peter
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Let me take a look at stackedbar drawing to see if it can work without taking
the absolute values. The results won't always make sense if positive and
negative values are mixed, but as long as the results are consistent and
explainable, I don't see why it needs to do abs().
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not as easy as I thought, but it does seem to be doable. The first non-zero value in a row will set the direction, up or down, for the rest of the bar. With all positive values, it looks the same as now (of course). With all negative values, the bar extends downward from the X axis with the first segment at the top. The labels and shading adjust for downward bars.
Mixing positive and negative values in a row is not recommended. It keeps the running total, but doesn't draw any segments in the wrong direction. The results are consistent and I think correct, but probably not useful.
Move the X axis and it properly clips bars that go in that direction, but it stretches bars that go in the other direction which looks odd. But I can't see a better way.
I still have to do the same fixes for horizontal stacked bars.
Sorry, there was a delay while I fixed a problem with axis positions that came
up while testing this change to stacked bar plots. It only affects horizontal
plots, and was a simple change but required a number of updates to the
reference manual. That's done now.
I just committed the change to CVS for negative values in stacked bar plots.
If you want to try it now, you can pull it right off the CVS web site under
Code, CVS Browse, select phplot, phplot.php and click download next to the
lastest version. Otherwise, if you want to wait for the next release, it won't
be too long. There is just one change in progress (to improve color handling).
It is already coded and just needs to be brought in sync with the latest
changes and retested, then it will likely be release time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If I understand what you want to do, you would use SetDataColors() to define 2 * N colors, then your data colors callback just returns (N * ($row % 2) + $col). Here N is the number of colors in each set, or the maximum number of segments in each bar.
Last edit: lbayuk 2012-12-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
is it possible to display negative datasets in a stacked bar plot?
eg
$data2 = array(
array('Mean Vario720 m/s',-10,-2),
array('Vario720 m/s',-20,2),
array('GPS Ht.Loss m', -30,8),
array('Baro.Ht.Loss m', -4,0)
);
thanks,
Peter
No, stacked bar plot doesn't support negative values. (In fact it takes the
absolute value of each value to avoid negative numbers.)
Since it is adding up the Y values for each X, I don't think having negative
values makes any sense. But I'm open to being convinced otherwise.
I suppose a stacked bar plot with all negative values would make sense, but
your data has a mixture of negative and positive values.
Hi,
what I'm really looking for is a way to display discrete datasets in bar-graph
form with an indication of the standard deviation of the dataset. I've got
some good looking results by (mis) using stacked bar display but now need to
account for some negative sets. It isn't a problem to make the set completely
negative.
Or can you suggest a different approach? Using a linepoint plot with error
bars is ok, but a bar graph display looks so much better.
Thanks,
Peter
Let me take a look at stackedbar drawing to see if it can work without taking
the absolute values. The results won't always make sense if positive and
negative values are mixed, but as long as the results are consistent and
explainable, I don't see why it needs to do abs().
Not as easy as I thought, but it does seem to be doable. The first non-zero value in a row will set the direction, up or down, for the rest of the bar. With all positive values, it looks the same as now (of course). With all negative values, the bar extends downward from the X axis with the first segment at the top. The labels and shading adjust for downward bars.
Mixing positive and negative values in a row is not recommended. It keeps the running total, but doesn't draw any segments in the wrong direction. The results are consistent and I think correct, but probably not useful.
Move the X axis and it properly clips bars that go in that direction, but it stretches bars that go in the other direction which looks odd. But I can't see a better way.
I still have to do the same fixes for horizontal stacked bars.
Sample with explanation can be found here: http://phplot.sourceforge.net/samples/negative_stacked_bars.php)
(The code shown requires a version of PHPlot which isn't even in CVS yet.)
Last edit: lbayuk 2012-12-11
The documentation looks good - let me know if you need a tester for the new
code!
Cheers,
Peter
I think I've got it all working. Some more testing, and I'll put it into CVS
and you will be able to try it out if you want.
I also opened a feature request for this. https://sourceforge.net/tracker/?func=detail&aid=3073679&group_id=14653&atid=364653
(Because I like to have a bug report or feature request number to reference at release time.)
Last edit: lbayuk 2012-12-11
Sorry, there was a delay while I fixed a problem with axis positions that came
up while testing this change to stacked bar plots. It only affects horizontal
plots, and was a simple change but required a number of updates to the
reference manual. That's done now.
I just committed the change to CVS for negative values in stacked bar plots.
If you want to try it now, you can pull it right off the CVS web site under
Code, CVS Browse, select phplot, phplot.php and click download next to the
lastest version. Otherwise, if you want to wait for the next release, it won't
be too long. There is just one change in progress (to improve color handling).
It is already coded and just needs to be brought in sync with the latest
changes and retested, then it will likely be release time.
Great - thanks a lot! that's really helped a lot.
Is there an easy way to make alternating columns in a stacked bar plot get
plotted with two sets of different colours?
Thanks,
Peter
You can control the colors within each stack using SetDataColors(). Normally, the corresponding segments in each stack have the same color. If you want more
control than that, you can use the Data Colors Callback. This is described here: http://phplot.sourceforge.net/phplotdocs/conc-colors-datacolor-callback.html with an example here: http://phplot.sourceforge.net/phplotdocs/ex-colorcallbackbars.html
If I understand what you want to do, you would use SetDataColors() to define 2 * N colors, then your data colors callback just returns (N * ($row % 2) + $col). Here N is the number of colors in each set, or the maximum number of segments in each bar.
Last edit: lbayuk 2012-12-11