cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
teoten
Level II

Create a graph using only selected rows

Hi,

 

I am trying to create a Graph using Graph Builder, or via script JSL, using only selected rows, without affecting the rest of the table. The example is the following:

 

I have a table like this

teoten_0-1621522351482.png

 

I need to create a dispersion plot of the values for category A - ONLY. I need to keep category B for some calculations, i.e. to define limits that will also be added to the plot as horizontal lines. Since I need to do it for several variables at the same time, I would prefer if you know a solution that does not requires the creation of a subset table - This would result in my script creating one new table per each variable I need to analyze. Or if you know a solution using subset table, but being able to close the new table at the end by keeping the plot actual it would work for me. I tried creating subset table with good results, but when I close it the values disappear, and I don't want to end up with several tables open or hidden. 

 

I tried also by hiding and excluding all the rows containing B before running the graph builder, the result is good, but then later when I clear the row statements all the values simply appear again in the graphic. I need to keep values with B without hiding and excluding because I also want to add a boxplot comparing each group (A and B).

 

Any ideas are welcome!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Create a graph using only selected rows

Here is a simple example, using your Example data that creates a graph with a Local Data Filter selecting only the A group data, and then hides the data filter from the display

filter.PNG

Names Default To Here( 1 );
dt = New Table( "Example",
	Add Rows( 8 ),
	New Column( "ID", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4, 5, 6, 7, 8] ) ),
	New Column( "Values",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1.1, 1.2, 1.3, 1.4, 1, 0.9, 0.8, 1.2] )
	),
	New Column( "Category", Character, "Nominal", Set Values( {"A", "A", "A", "A", "B", "B", "B", "B"} ) )
);


// Here is the graph code
biv =dt << Bivariate(
	Y( :Values ),
	X( :ID ),
	Local Data Filter(
		Close Outline( 1 ),
		Add Filter( columns( :Category ), Where( :Category == "A" ) )
	)
);

// Add this line if you do not want the collapsed Local Data Filter displayed
(report(biv)<<top parent)["Local Data Filter"]<<visibility("Collapse");

This should give you a good start

Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Create a graph using only selected rows

Here is a simple example, using your Example data that creates a graph with a Local Data Filter selecting only the A group data, and then hides the data filter from the display

filter.PNG

Names Default To Here( 1 );
dt = New Table( "Example",
	Add Rows( 8 ),
	New Column( "ID", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4, 5, 6, 7, 8] ) ),
	New Column( "Values",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1.1, 1.2, 1.3, 1.4, 1, 0.9, 0.8, 1.2] )
	),
	New Column( "Category", Character, "Nominal", Set Values( {"A", "A", "A", "A", "B", "B", "B", "B"} ) )
);


// Here is the graph code
biv =dt << Bivariate(
	Y( :Values ),
	X( :ID ),
	Local Data Filter(
		Close Outline( 1 ),
		Add Filter( columns( :Category ), Where( :Category == "A" ) )
	)
);

// Add this line if you do not want the collapsed Local Data Filter displayed
(report(biv)<<top parent)["Local Data Filter"]<<visibility("Collapse");

This should give you a good start

Jim
teoten
Level II

Re: Create a graph using only selected rows

Very elegant solution and it does exactly what I need. Thank you so much!

Deez_Data
Level I

Re: Create a graph using only selected rows

 I posted because I had a similar question... but I decided it was better to start a new thread. Mods, feel free to delete this post if it's possible. 

txnelson
Super User

Re: Create a graph using only selected rows

You can do what you want quite easily.

Here is an example using the Big Class sample data table.

txnelson_0-1677040414449.png

To generate the above graph

  1. Open the Sample data table, Big Class
  2. Open Graph Builder
  3. To compare 12 year olds to all of the individuals one just needs to create a virtual column where only the weights for 12 year olds are populated
    1. Right click on the weight column and select "Formula"
    2. When the formula dialog box opens, Right click on the new virtual column "Transform(weight)" and select "Rename"
    3. Rename the column to "Age 12 Weights"
    4. Now go to the actual formula and input the following formula
      If( :age == 12, :weight, . )
    5. Click OK
  4. In the Graph Builder window, 
    1. Drag both columns weight and Age 12 Weights to the Y axis drop area
    2. Right Click on the graph and select      Points=>Change to=>Box Plot

The above plot will then be produced

 

Jim