Plotting more than one distribution

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
J.
Posts: 17
Joined: Fri Jun 27, 2008 5:30 pm

Plotting more than one distribution

Post by J. » Sat Jun 28, 2008 12:08 pm

Further to my previous post, seems I do have another issue!

I need to produce a distribution plot for more than one group e.g.

Group 1: mean = 3, standard deviation = 1
Group 2: mean = 4, standard deviation = 1
Group 3: mean = 5, standard deviation = 1

And then plot the distribution for each group on the same chart, kind of like this:

i7.photobucket.com/albums/y260/-alsvartr-/dist.jpg

I understand how to plot a graph for each group seperately, but cannot combine them.

Code: Select all

/* Create function */
Function2D group1 = new NormalDistributionFunction2D(3.0, 1.0);
Function2D group2 = new NormalDistributionFunction2D(2.0, 1.0);
Function2D group3 = new NormalDistributionFunction2D(2.0, 1.0);

/* Create data set based on function */
XYDataset dataset = DatasetUtilities.sampleFunction2D(group1, -5.0, 5.0, 100, "Group1");
XYDataset dataset2 = DatasetUtilities.sampleFunction2D(group2, -5.0, 5.0, 100, "Group2");
Is there any way to combine these two datasets into one dataset and plot two distribution curves? Or is there a totally different way of approaching the problem?

Thanks!

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: Plotting more than one distribution

Post by RichardWest » Sat Jun 28, 2008 6:20 pm

J. wrote:Is there any way to combine these two datasets into one dataset and plot two distribution curves? Or is there a totally different way of approaching the problem?
Try to post all related questions in the same thread. Create the two datasets and then add the series from one of the datasets to the other. Not exactly fancy but quick. The other option would be to sample the distribution functions manually en masse and populate a single dataset.

If you want to draw integrals as you did in JFreeChart and Statistics, you will want to keep each distribution in separate datasets. A plot can plot multiple datasets, so there would be no issue displaying them. Just read through the JavaDoc entries.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

J.
Posts: 17
Joined: Fri Jun 27, 2008 5:30 pm

Re: Plotting more than one distribution

Post by J. » Sat Jun 28, 2008 7:35 pm

Thanks very much for your replies!
RichardWest wrote:If you want to draw integrals as you did in JFreeChart and Statistics, you will want to keep each distribution in separate datasets.
By using the first method you mentioned ("Create the two datasets and then add the series from one of the datasets to the other")?
A plot can plot multiple datasets, so there would be no issue displaying them. Just read through the JavaDoc entries.
Regarding the "JavaDoc entries", these are acquired through Ant, correct? Because I cannot for the life of me figure out how to install and use Ant. Is it important that I work this out? Does anyone know of an "idiot's guide" for doing this?

J.
Posts: 17
Joined: Fri Jun 27, 2008 5:30 pm

Re: Plotting more than one distribution

Post by J. » Sat Jun 28, 2008 7:46 pm

RichardWest wrote: Try to post all related questions in the same thread. Create the two datasets and then add the series from one of the datasets to the other. Not exactly fancy but quick. The other option would be to sample the distribution functions manually en masse and populate a single dataset.
Really sorry about this, but could you elaborate a little on these methods? I am no stats expert at all.

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: Plotting more than one distribution

Post by RichardWest » Sat Jun 28, 2008 7:47 pm

J. wrote:By using the first method you mentioned ("Create the two datasets and then add the series from one of the datasets to the other")?
No, use the method you were using to create the separate datasets via sampleFunction2D.
J. wrote:Regarding the "JavaDoc entries", these are acquired through Ant, correct? Because I cannot for the life of me figure out how to install and use Ant. Is it important that I work this out? Does anyone know of an "idiot's guide" for doing this?
If you want to learn Ant, you can find tutorials online. However, almost every open source project has their API documentation online. JFreeChart is no exception with its JavaDocs.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

J.
Posts: 17
Joined: Fri Jun 27, 2008 5:30 pm

Re: Plotting more than one distribution

Post by J. » Sat Jun 28, 2008 7:52 pm

RichardWest wrote: If you want to learn Ant, you can find tutorials online. However, almost every open source project has their API documentation online. JFreeChart is no exception with its JavaDocs.
So the on-line API doc and what you get from Ant is the same thing? I've been using the on-line API so far. I was just a little confused because in the jFreeChart installation guide it makes no mention of the on-line API so I had assumed it was something different I was missing out on!

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: Plotting more than one distribution

Post by RichardWest » Sat Jun 28, 2008 7:57 pm

J. wrote:So the on-line API doc and what you get from Ant is the same thing? I've been using the on-line API so far. I was just a little confused because in the jFreeChart installation guide it makes no mention of the on-line API so I had assumed it was something different I was missing out on!
The online API is the API that existed for the latest released version of JFreeChart (v1.0.10 at time of posting). This API might be slightly different from the API you would get by running Ant if you are using the latest revision of JFreeChart in the SVN repository. The differences, if any, should be minimal and inconsequential.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

J.
Posts: 17
Joined: Fri Jun 27, 2008 5:30 pm

Post by J. » Sat Jun 28, 2008 9:57 pm

Awesome, I have got it sorted now. Thanks every so much for your help!

Is there any way to reproduce the line indicating the mean, as shown in the example diagram I gave in that link earlier? The vertical line going from the x-axis through the distribution curve.

I imagine I would need to follow your advice in the link you gave me in my other thread in order to do such a thing.

J.
Posts: 17
Joined: Fri Jun 27, 2008 5:30 pm

Post by J. » Sat Jun 28, 2008 11:50 pm

J. wrote: Is there any way to reproduce the line indicating the mean, as shown in the example diagram I gave in that link earlier? The vertical line going from the x-axis through the distribution curve.
Aha, figured this out, by using a ValueMarker. Seems to be the best way!

Locked