cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
neelsrejan
Level III

Changing one color from the legend that is set to JMP Default for multiple graphs in variability chart

Hi all, 

 

My question is in two parts and ideally #1 can be solved, its okay if you can't figure out #2. I appreciate any and all help!

1. How can I make one of the categories within each legend be the color black and not the default color jmp assigns. 

Example: Make Chrysler the color black in the first legend, town car black in the second, 90 black in the third, 2 black in the fourth, and van black in the fifth?

2. How can I though a for loop add a legend to each variability chart. And likewise I want it to follow a certain pattern.

Example:In this case d airbag's legend is make, d&p airbags legend is model, manual belts is year, motorized belts is doors, and passive belts is size.

 

Variability Chart(
	SendToByGroup( {:"D/P"n == "Driver", :Protection == "d airbag"} ),
	Y( :Head IC ),
	SendToByGroup( {:"D/P"n == "Driver", :Protection == "d airbag"}, Y( :Head IC ) ),
	SendToByGroup(
		{:"D/P"n == "Driver", :Protection == "d&p airbags"},
		Y( :Head IC )
	),
	SendToByGroup(
		{:"D/P"n == "Driver", :Protection == "manual belts"},
		Y( :Head IC )
	),
	SendToByGroup(
		{:"D/P"n == "Driver", :Protection == "Motorized belts"},
		Y( :Head IC )
	),
	SendToByGroup(
		{:"D/P"n == "Driver", :Protection == "passive belts"},
		Y( :Head IC )
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "d airbag"},
		Y( :Head IC )
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "d&p airbags"},
		Y( :Head IC )
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "manual belts"},
		Y( :Head IC )
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "Motorized belts"},
		Y( :Head IC )
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "passive belts"},
		Y( :Head IC )
	),
	X( :Make, :Model ),
	Show Range Bars( 0 ),
	Show Cell Means( 0 ),
	Std Dev Chart( 0 ),
	Points Jittered( 1 ),
	By( :"D/P"n, :Protection ),
	SendToByGroup(
		{:"D/P"n == "Driver", :Protection == "d airbag"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Driver, Protection=d airbag",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Make,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	),
	SendToByGroup(
		{:"D/P"n == "Driver", :Protection == "d&p airbags"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Driver, Protection=d&p airbags",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Model,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	),
	SendToByGroup(
		{:"D/P"n == "Driver", :Protection == "manual belts"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Driver, Protection=manual belts",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Year,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	),
	SendToByGroup(
		{:"D/P"n == "Driver", :Protection == "Motorized belts"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Driver, Protection=Motorized belts",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Doors,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	),
	SendToByGroup(
		{:"D/P"n == "Driver", :Protection == "passive belts"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Driver, Protection=passive belts",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Size,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "d airbag"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Passenger, Protection=d airbag",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Make,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "d&p airbags"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Passenger, Protection=d&p airbags",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Model,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "manual belts"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Passenger, Protection=manual belts",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Year,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "Motorized belts"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Passenger, Protection=Motorized belts",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Doors,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	),
	SendToByGroup(
		{:"D/P"n == "Passenger", :Protection == "passive belts"},
		SendToReport(
			Dispatch(
				{"Variability Gauge D/P=Passenger, Protection=passive belts",
				"Variability Chart for Head IC"},
				"Variability Chart",
				FrameBox,
				{Row Legend(
					Size,
					Color( 1 ),
					Color Theme( "JMP Default" ),
					Marker( 0 ),
					Marker Theme( "" ),
					Continuous Scale( 0 ),
					Reverse Scale( 0 ),
					Excluded Rows( 0 )
				)}
			)
		)
	)
)

neelsrejan_0-1683342621109.png

neelsrejan_1-1683342636588.pngneelsrejan_2-1683342648377.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Changing one color from the legend that is set to JMP Default for multiple graphs in variability chart

Hopefully there are more simpler solutions than this very script heavy one using value colors column property, but this might get you going

Names Default To Here(1);

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

aa_protection_legend = Associative Array("Year"); // default value Year as I won't write all of these
aa_protection_legend["d airbag"] = "Make";
aa_protection_legend["d&p airbags"] = "Model";


cols_to_color = Associative Array();
cols_to_color["Make"] = "Chrysler";
cols_to_color["Model"] = "Town Car";


vars = dt << Variability Chart(
	SendToByGroup({:"D/P"n == "Driver", :Protection == "d airbag"}),
	Y(:Head IC),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "d airbag"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "d&p airbags"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "manual belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "Motorized belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "passive belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "d airbag"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "d&p airbags"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "manual belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "Motorized belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "passive belts"}, Y(:Head IC)),
	X(:Make, :Model),
	Show Range Bars(0),
	Show Cell Means(0),
	Std Dev Chart(0),
	Points Jittered(1),
	By(:"D/P"n, :Protection)
);

dt_colors = New Table("colors", New Column("color", Numeric, Ordinal, Values(1::1000)), invisible);
Column(dt_colors, "color") << Set Property("Value Colors", "JMP Default");
colors = Column(dt_colors, "color") << Get Property("Value Colors");
Close(dt_colors, no save);

set_color_property = function({dt, col_name, black_val}, {uniq, color_idx, property_list},
	Summarize(dt, uniq = by(eval(col_name)));
	color_idx = 1;
	property_list = "";
	For Each({val}, uniq,
		If(val == black_val,
			colorval = "\!"" || val || "\!" = 0";
		,
			colorval = "\!"" || val || "\!" = " || char(Arg(colors[color_idx], 2));
			color_idx++;
		);
		property_list = property_list || colorval || ", ";
	);

	property_list = "{" ||Regex(property_list, ", $", "", GLOBALREPLACE) ||"}";
	
	Eval(EvalExpr(Column(dt, col_name) << Set Property("Value Colors",
		Expr(Parse(property_list))
	)));
);

For Each({{key, val}}, cols_to_color,
	set_color_property(dt, key, val);
);


For Each({var, idx}, vars,
	rep = Report(var);
	framebox = rep[Frame Box(1)];
	
	cur_protection = Regex(rep << get title, ".*Protection=(.+)", "\1");
	
	framebox << Row Legend(
		Eval(aa_protection_legend[cur_protection]), 
		Color(1), 
		Color Theme(""),
		Marker(0), 
		Marker Theme(""), 
		Continuous Scale(0), 
		Reverse Scale(0), 
		Excluded Rows(0)
	);
);

jthi_0-1683356211222.png

 

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Changing one color from the legend that is set to JMP Default for multiple graphs in variability chart

Hopefully there are more simpler solutions than this very script heavy one using value colors column property, but this might get you going

Names Default To Here(1);

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

aa_protection_legend = Associative Array("Year"); // default value Year as I won't write all of these
aa_protection_legend["d airbag"] = "Make";
aa_protection_legend["d&p airbags"] = "Model";


cols_to_color = Associative Array();
cols_to_color["Make"] = "Chrysler";
cols_to_color["Model"] = "Town Car";


vars = dt << Variability Chart(
	SendToByGroup({:"D/P"n == "Driver", :Protection == "d airbag"}),
	Y(:Head IC),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "d airbag"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "d&p airbags"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "manual belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "Motorized belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Driver", :Protection == "passive belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "d airbag"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "d&p airbags"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "manual belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "Motorized belts"}, Y(:Head IC)),
	SendToByGroup({:"D/P"n == "Passenger", :Protection == "passive belts"}, Y(:Head IC)),
	X(:Make, :Model),
	Show Range Bars(0),
	Show Cell Means(0),
	Std Dev Chart(0),
	Points Jittered(1),
	By(:"D/P"n, :Protection)
);

dt_colors = New Table("colors", New Column("color", Numeric, Ordinal, Values(1::1000)), invisible);
Column(dt_colors, "color") << Set Property("Value Colors", "JMP Default");
colors = Column(dt_colors, "color") << Get Property("Value Colors");
Close(dt_colors, no save);

set_color_property = function({dt, col_name, black_val}, {uniq, color_idx, property_list},
	Summarize(dt, uniq = by(eval(col_name)));
	color_idx = 1;
	property_list = "";
	For Each({val}, uniq,
		If(val == black_val,
			colorval = "\!"" || val || "\!" = 0";
		,
			colorval = "\!"" || val || "\!" = " || char(Arg(colors[color_idx], 2));
			color_idx++;
		);
		property_list = property_list || colorval || ", ";
	);

	property_list = "{" ||Regex(property_list, ", $", "", GLOBALREPLACE) ||"}";
	
	Eval(EvalExpr(Column(dt, col_name) << Set Property("Value Colors",
		Expr(Parse(property_list))
	)));
);

For Each({{key, val}}, cols_to_color,
	set_color_property(dt, key, val);
);


For Each({var, idx}, vars,
	rep = Report(var);
	framebox = rep[Frame Box(1)];
	
	cur_protection = Regex(rep << get title, ".*Protection=(.+)", "\1");
	
	framebox << Row Legend(
		Eval(aa_protection_legend[cur_protection]), 
		Color(1), 
		Color Theme(""),
		Marker(0), 
		Marker Theme(""), 
		Continuous Scale(0), 
		Reverse Scale(0), 
		Excluded Rows(0)
	);
);

jthi_0-1683356211222.png

 

-Jarmo
neelsrejan
Level III

Re: Changing one color from the legend that is set to JMP Default for multiple graphs in variability chart

Hi jthi, 

 

Thanks for the response and that's a wonderful solution that opened a lot of other things in JSL I need to learn so I appreciate the response. Just out of curiosity, you made a colors column from 1-1000 and it looks like each has a slightly unique hex code, in the case that my data has say 5000 different values, can I change the script to 5000 or is 1000 the length of the color array and colors will repeat after?