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
lwx228
Level VIII

How can add another column of text to a graph?

For example, use "Big Class.jmp".
A text column has been added as follows.
And make a graph, the need to graph the new column text in the graph display.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt << New Column( "row", formula( Row() ) );
dt << run formulas;
Column( "row" ) << deleteFormula;
dt << Add Multiple Columns( "A", 2, Character, "Nominal" );
Column( dt, N Col( dt ) - 1 ) << set name( "max" );
Column( dt, N Col( dt ) ) << set name( "min" );
Column( "max" ) << Formula(
	If( height == Max( height[Index( Row() - 5, Row() + 5 )] ),
		name
	)
);
dt << run formulas;
Column( "max" ) << deleteFormula;
Column( "min" ) << Formula(
	If( height == Min( height[Index( Row() - 5, Row() + 5 )] ),
		name
	)
);
dt << run formulas;Column( "min" ) << deleteFormula;

c1 = Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :row ), Y( :height ) ),
	Elements( Line( X, Y, Legend( 5 ) ) )
);

2021-02-24_10-01-55.png

Thanks Experts!

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How can add another column of text to a graph?

I think this is what you want.  It creates the graph with only the Max column showing the labels, and then adds the Min column and the new labels show up.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:name << set labelled( 0 ); // Remove the default label

// Create the new row column
dt << New Column( "row", formula( Row() ) );
dt << run formulas;
Column( "row" ) << deleteFormula;

// Add the first label column
dt << New Column( "max", character,
	Formula(
		If( height == Max( height[Index( Row() - 5, Row() + 5 )] ),
			name
		)
	)
);
dt << run formulas;
Column( "max" ) << deleteFormula;
Column( "max" ) << set labelled( 1 );
dt << select where( :max != "" );
dt << Label;
dt << clear select;

// Run the graph
c1 = Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :row ), Y( :height ) ),
	Elements( Line( X, Y, Legend( 5 ) ), Points( X, Y, Legend( 6 ) ) )
);
Report( c1 )[framebox( 1 )] << Marker Size( 0 );

// Wait added to allow initial labeling before adding new labeling
Wait( 5 );

// Add new label column
dt << New Column( "min", character,
	Formula(
		If( height == Min( height[Index( Row() - 5, Row() + 5 )] ),
			name
		)
	)
);
dt << run formulas;
Column( "min" ) << deleteFormula;
Column( "min" ) << set labelled( 1 );
dt << select labeled;
dt << select where( :min != "", current selection( "extend" ) );
dt << Label;
dt << clear select;

Jim

View solution in original post

txnelson
Super User

Re: How can add another column of text to a graph?

By setting the RowState color to red for the rows where there are Max values, the displayed labels for those rows will be red.  I have added some code to the current script to handle the coloring.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:name << set labelled( 0 ); // Remove the default label

// Create the new row column
dt << New Column( "row", formula( Row() ) );
dt << run formulas;
Column( "row" ) << deleteFormula;

// Add the first label column
dt << New Column( "max", character,
	Formula(
		If( height == Max( height[Index( Row() - 5, Row() + 5 )] ),
			name
		)
	)
);
dt << run formulas;
Column( "max" ) << deleteFormula;
Column( "max" ) << set labelled( 1 );
dt << select where( :max != "" );
selectedRows = dt << get selected rows;
for(i=1,i<=NRows(selectedRows),i++,
	rowstate( selectedRows[i] ) = Color State ("red")
);
dt<<select where(:max !="");

dt << Label;
dt << clear select;

// Run the graph
c1 = Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :row ), Y( :height ) ),
	Elements( Line( X, Y, Legend( 5 ) ), Points( X, Y, Legend( 6 ) ) )
);
Report( c1 )[framebox( 1 )] << Marker Size( 0 );

// Wait added to allow initial labeling before adding new labeling
Wait( 5 );

// Add new label column
dt << New Column( "min", character,
	Formula(
		If( height == Min( height[Index( Row() - 5, Row() + 5 )] ),
			name
		)
	)
);
dt << run formulas;
Column( "min" ) << deleteFormula;
Column( "min" ) << set labelled( 1 );
dt << select labeled;

dt << select where( :min != "", current selection( "extend" ) );
dt << Label;
dt << clear select;
Jim

View solution in original post

9 REPLIES 9
lwx228
Level VIII

Re: How can I add another column of text to a graph?

I failed to find a solution through the graphic code of "Big Class Families".

Graph Builder(Size(535,455),
Variables(X(:row),Y(:height)),Elements(Line(X,Y,Legend(5))),
SendToReport(Dispatch({},"Graph Builder",FrameBox,
{Marker Size(2),{
Add Pin Annotation(Seg(Marker Seg(1)),Index(9),Index Row(9),UniqueID(1180683047),Origin({64.8386487250506,97.865127215503}),Offset({-239,8}),Tag Line)	
}})));

 

2021-02-24_16-28-57.png 

jthi
Super User

Re: How can I add another column of text to a graph?

This discussion might help:

How to add value label to points? 

-Jarmo
txnelson
Super User

Re: How can add another column of text to a graph?

I think this is what you want.  It creates the graph with only the Max column showing the labels, and then adds the Min column and the new labels show up.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:name << set labelled( 0 ); // Remove the default label

// Create the new row column
dt << New Column( "row", formula( Row() ) );
dt << run formulas;
Column( "row" ) << deleteFormula;

// Add the first label column
dt << New Column( "max", character,
	Formula(
		If( height == Max( height[Index( Row() - 5, Row() + 5 )] ),
			name
		)
	)
);
dt << run formulas;
Column( "max" ) << deleteFormula;
Column( "max" ) << set labelled( 1 );
dt << select where( :max != "" );
dt << Label;
dt << clear select;

// Run the graph
c1 = Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :row ), Y( :height ) ),
	Elements( Line( X, Y, Legend( 5 ) ), Points( X, Y, Legend( 6 ) ) )
);
Report( c1 )[framebox( 1 )] << Marker Size( 0 );

// Wait added to allow initial labeling before adding new labeling
Wait( 5 );

// Add new label column
dt << New Column( "min", character,
	Formula(
		If( height == Min( height[Index( Row() - 5, Row() + 5 )] ),
			name
		)
	)
);
dt << run formulas;
Column( "min" ) << deleteFormula;
Column( "min" ) << set labelled( 1 );
dt << select labeled;
dt << select where( :min != "", current selection( "extend" ) );
dt << Label;
dt << clear select;

Jim
lwx228
Level VIII

Re: How can add another column of text to a graph?

Thank Jim!

 

2021-02-24_21-13-35.png

lwx228
Level VIII

Re: How can add another column of text to a graph?

How to use JSL to implement just will:the font for the "MAX" column is set to red.

Thanks Experts!

2021-02-25_07-23-32.png

txnelson
Super User

Re: How can add another column of text to a graph?

By setting the RowState color to red for the rows where there are Max values, the displayed labels for those rows will be red.  I have added some code to the current script to handle the coloring.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:name << set labelled( 0 ); // Remove the default label

// Create the new row column
dt << New Column( "row", formula( Row() ) );
dt << run formulas;
Column( "row" ) << deleteFormula;

// Add the first label column
dt << New Column( "max", character,
	Formula(
		If( height == Max( height[Index( Row() - 5, Row() + 5 )] ),
			name
		)
	)
);
dt << run formulas;
Column( "max" ) << deleteFormula;
Column( "max" ) << set labelled( 1 );
dt << select where( :max != "" );
selectedRows = dt << get selected rows;
for(i=1,i<=NRows(selectedRows),i++,
	rowstate( selectedRows[i] ) = Color State ("red")
);
dt<<select where(:max !="");

dt << Label;
dt << clear select;

// Run the graph
c1 = Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :row ), Y( :height ) ),
	Elements( Line( X, Y, Legend( 5 ) ), Points( X, Y, Legend( 6 ) ) )
);
Report( c1 )[framebox( 1 )] << Marker Size( 0 );

// Wait added to allow initial labeling before adding new labeling
Wait( 5 );

// Add new label column
dt << New Column( "min", character,
	Formula(
		If( height == Min( height[Index( Row() - 5, Row() + 5 )] ),
			name
		)
	)
);
dt << run formulas;
Column( "min" ) << deleteFormula;
Column( "min" ) << set labelled( 1 );
dt << select labeled;

dt << select where( :min != "", current selection( "extend" ) );
dt << Label;
dt << clear select;
Jim
lala
Level VIII

Re: How can add another column of text to a graph?

How can I modify the interval markers to use different colors?

Big Class.jmp uses this script to plot, "B" lists the height values of different ages by the number of rows to start and end.

The "B" column data that needs to be marked with the value of this B column as the interval, but requires the number of rows at the end of the age, is marked in red.

Thank Jim!

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Sort( By( age ), Order( Ascending ), replace table );
ca = "B";
r = N Row( dt );
New Column( ca );
Column( ca ) << Formula( If( Row() == r | Row() == 1 | age != Lag( age, 1 ) | age != Lag( age, -1 ), height ) );
dt << run formulas;
Column( ca ) << deleteFormula;

p1 = dt << Graph Builder(
	Variables( X( :weight ), Y( :height ), Group X( :age ), Color( :sex ), Interval( :B ) ),
	Elements( Bar( X, Y, Legend( 7 ), Response Axis( "X" ) ) )
);

2023-11-14_22-06-35.png

 

txnelson
Super User

Re: How can add another column of text to a graph?

By default, in JMP 17, the error bars take on the color specified by the "Color" variable.  In previous versions, the color was only determined by the color setting in the Customize Graph window.  However, only one color can be used.  Therefore, if you set the Error Bar color to Red, both the error bars for M and F would be red.

Jim
lala
Level VIII

Re: How can add another column of text to a graph?

OK、Thank Jim!