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
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!
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
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
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
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
Very elegant solution and it does exactly what I need. Thank you so much!
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.
You can do what you want quite easily.
Here is an example using the Big Class sample data table.
To generate the above graph
If( :age == 12, :weight, . )
The above plot will then be produced