cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
JDA
JDA
Level II

How do I add multiple data to the same graph?

Good morning/afternoon everyone.  

 

I feel like this should be really very straight forward, but I am struggling to work out how to do this.  In OriginPro this is really easy, but I am having to use JMP for work for the first time and so I am a total novice with this program.  

 

The problem: I have two sets of XRD data.  One from an older machine, one from a brand new machine.  The data is taken over the same domain, from roughly -6000 to +3000 arc seconds.  However, the spacing of the data points is different between the two machines.  

 

So I have these two datasets and I need to overlay them on the same plot.  Definitions of x (angle in arcseconds) and y (intensity in CPS) are the same.  

 

For both data sets the main reflection occurs at approximately 0 arcseconds (as expected).  Attached are plots of data from the two machines (D1 and V1).  

 

I have tried to use Graph Builder to add these data to the same graph, to overlay one on top of the other.  I have tried dragging both x domains to the x axis, but this does not result in the desired behaviour.  Rather than D1 being plotted against "it's" x, and V1 being plotted "it's" x, both data sets are being plotted using only one of the x ranges.  So this results in one of the datasets being either compressed or stretched, depending which x is used.  Attached is both datasets plotted in graph builder, and you can see the problem.  

 

All I want is the x range to be fixed, and for the multiple y to be plotted against an x axis.  

 

Given that I am still new to JMP an interactive solution would be preferable, but if a script is the only possible way then I will accept that as well.  

 

Thanks in advance for your help.  

V1V1

D1D1

D1+V1D1+V1

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: How do I add multiple data to the same graph?

Here's the table:

pmroz_0-1625059014913.png

Here's the resulting graph:

pmroz_1-1625059040249.png

 

View solution in original post

8 REPLIES 8
txnelson
Super User

Re: How do I add multiple data to the same graph?

The data for the graph has to come from a single data table.  Therefore, what you need to do is to take your 2 data tables and join or concatenate them together so you end up with your 1 X column, and 2 Y columns.  Then all you need to do is to open Graph Builder and drag the X column to the X drop area, and then select both of the Y columns and drag them to the Y drop area

Use

     Tables=>Join

or

     Tables=>Concatenate

to put the data together.  Make sure the X column name is the same in both data tables, and the Y column names are different.

Jim
pmroz
Super User

Re: How do I add multiple data to the same graph?

Here's one way to do it:

  • Add a column to each of your datasets, e.g. "Machine".  The value in the V1 table would be V1, and in the P1 table it would be P1.
  • Now concatenate the two tables.
  • Run graph builder and drag Omega to X, and the Y column to Y
  • Drag Machine to Overlay

Here's some code that shows how to do it:

dt = New Table( "Test Combo", Add Rows( 6 ),
	New Column( "Omega", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2, 3, 1, 2, 3] ) ),
	New Column( "Y", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 4, 10, 2, 7, 20] ) ),
	New Column( "Machine", Character, "Nominal",
		Set Values( {"D1", "D1", "D1", "V1", "V1", "V1"} ) )
);

dt << Graph Builder( Size( 527, 452 ), Show Control Panel( 0 ),
	Variables( X( :Omega ), Y( :Y ), Overlay( :Machine ) ),
	Elements( Line( X, Y, Legend( 13 ) ) ),
	SendToReport( Dispatch( {}, "Y", ScaleBox,
			{Scale( "Log" ), Format( "Best", 12 ), Min( 0.7 ),
			Max( 20.3648979591837 ), Inc( 1 ), Minor Ticks( 1 )}
		)
	)
);
pmroz
Super User

Re: How do I add multiple data to the same graph?

Here's the table:

pmroz_0-1625059014913.png

Here's the resulting graph:

pmroz_1-1625059040249.png

 

JDA
JDA
Level II

Re: How do I add multiple data to the same graph?

That works, but that is such an awful hack.  

 

Is this really the only way to do this?  There's genuinely no easier way to get something as basic as this done?  

Re: How do I add multiple data to the same graph?

The identified solution is the way to to do it. I have included another example to show that the "two sets of data" do not need to have the same x-values.

 

I believe the main issue that you are having is how to set up the data correctly. Think in terms of variables. You have an X variable (I think it is called Omega). You have Y-values (I believe it is called Velox??). You have a third variable called Machine. Your data table should have three columns, one for each variable, just as @pmroz showed.

 

His solution showed a JMP script because that is the easiest way to demonstrate a solution in this forum. But the interactive steps are quite easy once the data is set up properly. So here is an example table:

Dan_Obermiller_0-1625149304447.png

Go to Graph > Graph Builder.

Drag Omega to the X-axis. Drag Velox to the Y-axis. Drag Machine to the Overlay field.

I clicked the smoother button to remove the smoother.

Held the shift key and selected the line element button to add that.

Dan_Obermiller_1-1625149472990.png

Depending on how you count, that is 5 steps, once you have the data setup properly by thinking in terms of variables.

 

 

Dan Obermiller
JDA
JDA
Level II

Re: How do I add multiple data to the same graph?

The data are both in the same data table, but to reiterate, the problem is that they do not share the same set of x values, so your answer does not work.  

pmroz
Super User

Re: How do I add multiple data to the same graph?

I've put together a script that should do what you want.  It starts with a table with four columns: x1, y1, x2, y2. 

pmroz_0-1625596521472.png

The problem is that you need to stack x2 and y2 below x1 and y1, and add a column differentiating the two sets of data.  This is the sort of result you want to end up with:

pmroz_1-1625596567311.png

Here's the script.  Note that the first few lines define a table similar to yours, referenced by the variable dt.  

// Create an example table
dt = New Table( "Untitled 2", Add Rows( 4 ), 
	New Column( "x1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
	New Column( "y1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 2, 3, 1] ) ),
	New Column( "x2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 5, 7, 8] ) ),
	New Column( "y2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [5, 2, 8, 2] ) )
);

// For your case you would point the dt variable to your own table.
// dt = data table("My Data Table");

nr = nrows(dt);

// Make the new table
newdt = New Table( "Untitled 5",
	Add Rows( 2 * nr ),
	New Column( "x", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "y", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "Machine", Character, "Nominal")
);

// In the next section of code, replace x1 and y1 with your column names for the first x-y pair
// Start with X1, Y1
for (i = 1, i <= nr, i++,
	newdt:x[i] = dt:x1[i];
	newdt:y[i] = dt:y1[i];
	newdt:Machine[i] = "A";
);

// In this section of code, replace x2 and y2 with your column names for the second x-y pair
// Now add X2, Y2
for (i = (nr + 1), i <= 2 * nr, i++,
	newdt:x[i] = dt:x2[i - nr];
	newdt:y[i] = dt:y2[i - nr];
	newdt:Machine[i] = "B";
);

// Create the graph
newdt << Graph Builder(
	Size( 886, 452 ),
	Show Control Panel( 0 ),
	Variables( X( :x ), Y( :y ), Overlay( :Machine ) ),
	Elements( Line( X, Y, Legend( 13 ) ), Points( X, Y, Legend( 14 ) ) )
);

To run this code, copy it to the clipboard.  In JMP hit CTRL-T to open up a new script window, paste the code, and then hit CTRL-R to run it.

pmroz_2-1625597200307.png

I would have preferred to come up with an easier solution using Tables > Stack, but couldn't figure out how to make that work (here's a challenge for all you JMP users!).  This script is the next best thing. 

o129041voo
Level II

Re: How do I add multiple data to the same graph?

Hi,

 

I frequently use 2 sets of data (X1/Y1, X2/Y2), both in different columns, and overlay them into one XY graph.  Currently, I'd end up having 4 plots in one graph (X1/Y1, X1/Y2, X2/Y1, X2/Y2, I only need X1/Y1 & X2/Y2).  It always takes me half a day just to get the plot right.  

 

Thanks to JDA, I'm glad to know I'm not alone in this.  

 

I really appreciate if JMP can create an interactive solution to this in Ver 18.