- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Create a graph using only selected rows
Very elegant solution and it does exactly what I need. Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
To generate the above graph
- Open the Sample data table, Big Class
- Open Graph Builder
- 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
- Right click on the weight column and select "Formula"
- When the formula dialog box opens, Right click on the new virtual column "Transform(weight)" and select "Rename"
- Rename the column to "Age 12 Weights"
- Now go to the actual formula and input the following formula
If( :age == 12, :weight, . )
- Click OK
- In the Graph Builder window,
- Drag both columns weight and Age 12 Weights to the Y axis drop area
- Right Click on the graph and select Points=>Change to=>Box Plot
The above plot will then be produced