Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
eliyahu100
Level III

Bar graph of split column

Hi,
I have a table with many columns. one is a binary variable with 0,1 and lables 0=No, 1=Yes.
Another is a formula column based on several others which is categorical with the numbers 0-5.
I would like to create a bar graph with the categorical column on the x axis and the percentage of yes in each category as the y axis.
I could obtain this data by splitting the table using these two columns (split by = the categorical column and split column= binary column) and then get the distribution of all columns (=original categories), and look at the prob of Yes.

but how do I get this in a bar graph?
this is a pic of the spited data:

morad2.JPG

and this is a pic of the kind of graph i would like to create:

morad1.JPG

TIA

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Bar graph of split column

This can be accomplished fairly simply using 

     Analyze==>Tabulate

and then graphing the data from the resulting table

tab.PNG

  1. Start with your 2 columns, the one with 0-1 values and the other with your 0-4 values. Both columns need to have a modeling type of Ordinal.  I have called the rows, "Intervention" and "Number of Positive Risk Factors". 
    1. Place "intervention as a column grouping variable
    2. Place "Number of Positive Risk Factors" as a row grouping variable
    3. Set the statistic as Row %                          tab2.PNG
  2. Go to the red triangle and select "Make into Data Table"tab3.PNG
  3. Change the name of the Column "Row %(1)" to "Rate of Intervention"tab4.PNG
  4. Go to Graph Builder and create the graph
    1. Drag "Number of Positive Risk Factors" to the X axis
    2. Drag "Rate of Intervention" to the Y axis
    3. Click on the Bar Graph icon to change the graph to a bar chart
    4. In the Bar details section on the left side of the window, change the Label to "Label by Value"

Here is a script that produces the above 

Names Default to Here(1);
dt=new table("Example",
	add rows(400),
	new column("Intervention", ordinal, set each value(Random Integer(0,1))),
	new column("Number of Positive Risk Factors",ordinal,set each value(Random Integer(0,4)))
);

// Calculate the Statistic
tab = dt << Tabulate(invisible,
	Add Table(
		Column Table( Grouping Columns( :Intervention ), Statistics( Row % ) ),
		Row Table( Grouping Columns( :Number of Positive Risk Factors) )
	)
);
dtFinal = tab << make into data table;

// Change Column Name
dtFinal:Name("Row %(1)") << Set Name("Rate of Intervention");

// Create Graph
Graph Builder(
	Size( 534, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :Number of Positive Risk Factors ), Y( :Rate of Intervention ) ),
	Elements( Bar( X, Y, Legend( 6 ), Label( "Label by Value" ) ) )
);
Jim

View solution in original post

1 REPLY 1
Highlighted
txnelson
Super User

Re: Bar graph of split column

This can be accomplished fairly simply using 

     Analyze==>Tabulate

and then graphing the data from the resulting table

tab.PNG

  1. Start with your 2 columns, the one with 0-1 values and the other with your 0-4 values. Both columns need to have a modeling type of Ordinal.  I have called the rows, "Intervention" and "Number of Positive Risk Factors". 
    1. Place "intervention as a column grouping variable
    2. Place "Number of Positive Risk Factors" as a row grouping variable
    3. Set the statistic as Row %                          tab2.PNG
  2. Go to the red triangle and select "Make into Data Table"tab3.PNG
  3. Change the name of the Column "Row %(1)" to "Rate of Intervention"tab4.PNG
  4. Go to Graph Builder and create the graph
    1. Drag "Number of Positive Risk Factors" to the X axis
    2. Drag "Rate of Intervention" to the Y axis
    3. Click on the Bar Graph icon to change the graph to a bar chart
    4. In the Bar details section on the left side of the window, change the Label to "Label by Value"

Here is a script that produces the above 

Names Default to Here(1);
dt=new table("Example",
	add rows(400),
	new column("Intervention", ordinal, set each value(Random Integer(0,1))),
	new column("Number of Positive Risk Factors",ordinal,set each value(Random Integer(0,4)))
);

// Calculate the Statistic
tab = dt << Tabulate(invisible,
	Add Table(
		Column Table( Grouping Columns( :Intervention ), Statistics( Row % ) ),
		Row Table( Grouping Columns( :Number of Positive Risk Factors) )
	)
);
dtFinal = tab << make into data table;

// Change Column Name
dtFinal:Name("Row %(1)") << Set Name("Rate of Intervention");

// Create Graph
Graph Builder(
	Size( 534, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :Number of Positive Risk Factors ), Y( :Rate of Intervention ) ),
	Elements( Bar( X, Y, Legend( 6 ), Label( "Label by Value" ) ) )
);
Jim

View solution in original post

Article Labels