Subscribe Bookmark RSS Feed

Create Bar Graphs for Multiple Samples at Once with X Axis Labels

Lharbicht

New Contributor

Joined:

Nov 15, 2016

Help!

 

I have a large dataset of environmental sample data with columns for 29 different chemical compounds, and over a thousand rows of samples. We have an excel template that makes bar graphs for us that look like the uploaded picture. One graph is created for each sample, all the bars in the graph are the same colour and the x-axis is labeled with the chemical name. Is there a way to take my data in JMP 13 and create one bar graph for each sample using the 29 different chemicals and have it look similar to the uploaded picture? We most likely wouldn't be creating a plot for all thousand samples at once, but would select multiple rows of samples that we are interested in and would like to create graphs for those selected samples with a few clicks of the mouse.

 

Please let me know if this is possible.

 

Thank you for your help.

 

Lharbicht

 

Slide1.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution
Lacey,
Everything I did in the script, came from running interactively. In fact, the first example I gave could very easily be done interactively. Just take a look at the script, and you can see the steps it takes, and you can just mimic them interactively.
Jim
4 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Here is a script that creates a data table, with an embedded script.  Just select the rows(Samples) you want graphed, and then click on the embedded script and run it.

New Table( "Sample Data Table",
	Add Rows( 10 ),
	New Script(
		"Graph Selected Samples",
		Names Default To Here( 1 );
		dt = Current Data Table();
		dttemp = dt << subset(
			selected columns( 0 ),
			selected rows( 1 ),
			invisible
		);
		dtstacked = dttemp << Stack(
			invisible,
			columns(
				:NAP,
				:Name( " C1 NAP" ),
				:C2 NAP,
				:C3 NAP,
				:C4 NAP,
				:FLU,
				:C1 FLU,
				:C2 FLU,
				:C3 FLU,
				:Name( "PHE/ANT" ),
				:Name( "C1 PHE/ANT" ),
				:Name( "C2 PHE/ANT" ),
				:Name( "C3 PHE/ANT" ),
				:Name( "C4 PHE/ANT" ),
				:DBT,
				:C1 DBT,
				:C2 DBT,
				:C3 DBT,
				:C4 DBT,
				:Name( "FLRN/PYR" ),
				:Name( "C1 FLRN/PYR" ),
				:Name( "C2 FLRN/PYR" ),
				:Name( "C3 FLRN/PYR" ),
				:Name( "C4 FLRN/PYR" ),
				:Name( "BaA/CHR" ),
				:Name( "C1 BaA/CHR" ),
				:Name( "C2 BaA/CHR" ),
				:Name( "C3 BaA/CHR" ),
				:Name( "C4 BaA/CHR" )
			),
			Source Label Column( "Chemical Compound" ),
			Stacked Data Column( "Data" )
		);
		Close( dttemp, nosave );
		dtstacked:Chemical Compound << set property( "Row Order Levels", 1 );
		gb = dtstacked << Graph Builder(
			Size( 534, 1464 ),
			Show Control Panel( 0 ),
			Variables( X( :Chemical Compound ), Y( :Data ), Page( :Sample ) ),
			Elements( Bar( X, Y, Legend( 6 ) ) ),
			SendToReport(
				Dispatch(
					{},
					"400",
					ScaleBox,
					{Legend Model( 6, Properties( 0, {Fill Color( 45 )} ) )}
				),
				Dispatch( {}, "400", LegendBox, {Set Title( "" )} )
			)
		);
		gb << on close( Close( dtstacked, nosave ) );
	),
	New Column( "Sample",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] )
	),
	New Column( "NAP",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.002, 0.0302537593550514, 0.0466926784946118, 0.0448445924471598,
			0.0478487853344995, 0.0154921119890641, 0.0365249534228351,
			0.00493989895819686, 0.0235698992158286, 0.0381656375704333]
		)
	),
	New Column( " C1 NAP",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.019, 0.00774147778982297, 0.029915005012881, 0.0468929482218809,
			0.0092733804017771, 0.036089365969412, 0.00376344798482023,
			0.00380945356236771, 0.00193938017473556, 0.0489603107678704]
		)
	),
	New Column( "C2 NAP",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.08, 0.0270089123100042, 0.0226710953088477, 0.0259517372348346,
			0.0184357883431949, 0.0128242306013126, 0.00318159612896852,
			0.0317445193028543, 0.0380520822689868, 0.0067287613407243]
		)
	),
	New Column( "C3 NAP",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.115, 0.0283634321223944, 0.0348076855710242, 0.0318920150578488,
			0.0173453791385982, 0.0222847076184116, 0.0346989600521047,
			0.0143180883196183, 0.0327768972115591, 0.0222957084132358]
		)
	),
	New Column( "C4 NAP",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.09, 0.00166843675868586, 0.0287732524415478, 0.0219370269028004,
			0.0127755957059562, 0.0223023804044351, 0.0351790483894292,
			0.0249330674058292, 0.020071810176596, 0.0424596724130679]
		)
	),
	New Column( "FLU",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.003, 0.0138887988573406, 0.038354084254941, 0.0252995605911128,
			0.0154636751729995, 0.0433928036768921, 0.0134715204646345,
			0.0445313894778956, 0.0290542597356252, 0.0141719027855434]
		)
	),
	New Column( "C1 FLU",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.018, 0.0293069139991421, 0.0256769686636981, 0.00826683883252553,
			0.0171085286648013, 0.0204629610797856, 0.00341956458706409,
			0.0313640460087918, 0.0480407851564232, 0.0340318603476044]
		)
	),
	New Column( "C2 FLU",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.038, 0.0330850324584171, 0.0437534969407134, 0.0109815957569517,
			0.00449292429722846, 0.0132446803962812, 0.0386687645141501,
			0.0415801736263093, 0.034111307727173, 0.00602988170552999]
		)
	),
	New Column( "C3 FLU",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.082, 0.0477887129648589, 0.0355156372459605, 0.041393784352811,
			0.015643085104879, 0.00226023636339232, 0.0251587821198627,
			0.0304925097427331, 0.0429695688353386, 0.0474338214022573]
		)
	),
	New Column( "PHE/ANT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.01, 0.0427148100999184, 0.0202775471704081, 0.0149288747075479,
			0.00559148345608264, 0.0421801740452647, 0.0240726777378004,
			0.0209547791823279, 0.0244350242365617, 0.0497362994323485]
		)
	),
	New Column( "C1 PHE/ANT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.039, 0.00280673243640922, 0.0199594784926157, 0.0329235823897179,
			0.01066317764204, 0.0144819677001797, 0.00979254531022161,
			0.0220209252389614, 0.038684288996039, 0.0127347022991162]
		)
	),
	New Column( "C2 PHE/ANT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.06, 0.0486931873387657, 0.0215076145802159, 0.0244833285761997,
			0.0286523971226998, 0.0172093356093392, 0.0289594860547222,
			0.0275001738960855, 0.0266731308130547, 0.0466893218264449]
		)
	),
	New Column( "C3 PHE/ANT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.069, 0.0446601634738035, 0.0138321250828449, 0.0425168035281822,
			0.0366099622820038, 0.0274317172830924, 0.0353664513374679,
			0.00111495549138635, 0.0135933586545289, 0.00108291531680152]
		)
	),
	New Column( "C4 PHE/ANT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.031, 0.0144599841590971, 0.009610575562343, 0.0302202351707965,
			0.0212843791709747, 0.0115216388173867, 0.0468299421959091,
			0.00549429435911588, 0.0363094289952423, 0.0336387161160819]
		)
	),
	New Column( "DBT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.003, 0.0333379577584565, 0.00272550118085928, 0.0372126542304177,
			0.00271068549877964, 0.0312318569093477, 0.00354533990845084,
			0.0220444895469118, 0.021050514069153, 0.0383053797436878]
		)
	),
	New Column( "C1 DBT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.033, 0.0116053564054891, 0.0124466585058253, 0.0438335321764462,
			0.00124102681153454, 0.044037665597396, 0.0495759285241365,
			0.0475604402602185, 0.0456430103564635, 0.0310628124901559]
		)
	),
	New Column( "C2 DBT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.087, 0.0159295270822477, 0.0102833600859158, 0.0239058316384908,
			0.0178571299198084, 0.0348719786126167, 0.00821598792239092,
			0.00843277889839373, 0.0452348746119533, 0.01068949145847]
		)
	),
	New Column( "C3 DBT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[., 0.00672533513652161, 0.013112988761859, 0.0330644477382302,
			0.0482545678631868, 0.0133067361686844, 0.0265975029869005,
			0.0381060357526876, 0.0430836911720689, 0.049541658553062]
		)
	),
	New Column( "C4 DBT",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.034, 0.0058728216253221, 0.0217233841579873, 0.0402756876784842,
			0.0313993025359232, 0.029122445494635, 0.0155939766000956,
			0.0420744900063146, 0.0285329493524041, 0.0489617482072208]
		)
	),
	New Column( "FLRN/PYR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.001, 0.0345496558696032, 0.0321322070148308, 0.0267007229174487,
			0.0259779584354255, 0.0283408940385561, 0.0373562634971458,
			0.0393744796728715, 0.0145546169539448, 0.0282392732428852]
		)
	),
	New Column( "C1 FLRN/PYR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.01, 0.0409959553205408, 0.0325308263734914, 0.049760709581431,
			0.0423577155969106, 0.0143415241884068, 0.0192488916243892,
			0.0224930502227508, 0.0348894201670773, 0.0425700373509899]
		)
	),
	New Column( "C2 FLRN/PYR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.019, 0.00380003489204682, 0.0340351563671138, 0.0209355363992509,
			0.0493748148838058, 0.0330725406832062, 0.0281902657279279,
			0.015132855331758, 0.00606476198509335, 0.026483667955501]
		)
	),
	New Column( "C3 FLRN/PYR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.041, 0.0477709266166203, 0.0290582531234249, 0.0284437057543546,
			0.0460180501651484, 0.0212978765433654, 0.00925033876067028,
			0.0150167961854022, 0.00671246657753363, 0.0208397668299731]
		)
	),
	New Column( "C4 FLRN/PYR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.03, 0.0333795196467545, 0.0334625377673656, 0.0027455012050923,
			0.0280089165221434, 0.0129167727059685, 0.0241117861049715,
			0.00186966460011899, 0.0295675685461611, 0.0391173240377102]
		)
	),
	New Column( "BaA/CHR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.005, 0.0472474740443286, 0.0311875404128805, 0.0246964252435137,
			0.0193766511015128, 0.0417157581949141, 0.037641080430476,
			0.0216226827097125, 0.0370904210142326, 0.00173414511815645]
		)
	),
	New Column( "C1 BaA/CHR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.008, 0.0445609674151055, 0.00482703192089684, 0.00970582901337184,
			0.0416694305497222, 0.00920417479611933, 0.0252414871286601,
			0.0213213407513686, 0.0301611067913473, 0.0423710284563713]
		)
	),
	New Column( "C2 BaA/CHR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.026, 0.0127562464796938, 0.00709548401203938, 0.0126328233701643,
			0.0460777241429314, 0.0249449488269165, 0.0261664025301579,
			0.0219898488600738, 0.0486704192098696, 0.0349820018485188]
		)
	),
	New Column( "C3 BaA/CHR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.01, 0.0036289812636096, 0.0457750377375633, 0.00400210773036815,
			0.0182483235485852, 0.00714060053229332, 0.0418625881380867,
			0.00615676692244597, 0.0475078795051668, 0.026821686824318]
		)
	),
	New Column( "C4 BaA/CHR",
		Numeric,
		"Continuous",
		Format( "Percent", 7, 2 ),
		Set Values(
			[0.004, 0.0381506804318633, 0.0201645611631684, 0.0330415739305317,
			0.0110197423135396, 0.0322338481522165, 0.0153273207338061,
			0.0281656794969458, 0.0119208308472298, 0.0111531151456293]
		)
	)
)

Here is some sample output from the script

sample selection script output.png

This simple script will handle up to 100 Samples.  That limitation can easily be overcome.  Additionally, the grid lines you had in your sample can be added.  The script would just have to become a little smarter to do that.

 

But you were looking just for the posibility that JMP could do what you want, and I think this clearly shows you that it can.

Jim
txnelson

Super User

Joined:

Jun 22, 2012

Here is an update to the script I previously sent.  It better matches your suggested output.  It also allows you to run multiple sets of selections, without the outputs stomping on each other.  There also is no uppler limit(other than memory on your computer) to the number of Samples you want to run.

You can either take this script and embed it into the data table from the first response I made, or you can run it as a separate standalone script.  In either case, just select the rows(samples) you want to include in the output, and then run the script.

Names Default To Here( 1 );
dt = Current Data Table();

// Get the selected rows from the primary data table
dttemp = dt << subset( selected columns( 0 ), selected rows( 1 ), invisible );

// Create a random value to be used for this running of the script.
// This is to make the values in this run unique to this run, incase
// multiple runs are made against the data table, without closing the output
TheRandom = Char( Random Integer( 1, 100000000 ) );

// Wrap the code in a Substitution function, to add the TheRandom to the steps
// that need to be kept unique. __xxx__ indicates the areas where substitution
// has to be made
Eval(
Substitute(
Expr(
// Make a list of the data tables this execution of the code
// will make, so they can be closed when the output window is
// closed
__DataTableList__ = {};
// Create the initial window
__nw__ = New Window( "Product Sample", TheVLB = V List Box() );
// This is the code that will be run when the above window is closed
__nw__ << on close(
For( i = 1, i <= N Items( __DataTableList__ ), i++,
Try( Close( Data Table( __DataTableList__[i]), nosave ) )
)
);
// Loop across all of the rows in the data table created from the
// selected rows in the original data table
For( loop = 1, loop <= N Rows( dttemp ), loop++,
// Create a new data table for each row
dttemp << clear select;
dttemp << select rows( loop );
dttemp1 = dttemp << subset(
selected rows( 1 ),
selected columns( 0 ),
invisible
);
// Stack the one row table to make transform it to the structure
// that Graph Builder can best use it
dtstacked = dttemp1 << Stack(
invisible,
columns(
:NAP,
:Name( " C1 NAP" ),
:C2 NAP,
:C3 NAP,
:C4 NAP,
:FLU,
:C1 FLU,
:C2 FLU,
:C3 FLU,
:Name( "PHE/ANT" ),
:Name( "C1 PHE/ANT" ),
:Name( "C2 PHE/ANT" ),
:Name( "C3 PHE/ANT" ),
:Name( "C4 PHE/ANT" ),
:DBT,
:C1 DBT,
:C2 DBT,
:C3 DBT,
:C4 DBT,
:Name( "FLRN/PYR" ),
:Name( "C1 FLRN/PYR" ),
:Name( "C2 FLRN/PYR" ),
:Name( "C3 FLRN/PYR" ),
:Name( "C4 FLRN/PYR" ),
:Name( "BaA/CHR" ),
:Name( "C1 BaA/CHR" ),
:Name( "C2 BaA/CHR" ),
:Name( "C3 BaA/CHR" ),
:Name( "C4 BaA/CHR" )
),
Source Label Column( "Chemical Compound" ),
Stacked Data Column( "Data" )
);
// Close the no longer needed single row data table
Close( dttemp1, nosave );
// Set Row Order Level for the Chemical Compound column, which
// will order the axis on the graph in the order the data are
// found in the data table
dtstacked:Chemical Compound << set property( "Row Order Levels", 1 );
// Insert this table in the DataTableList, because it will remain
// open until the output window is closed
Insert Into( __DataTableList__, dtstacked << get name );
// Append to the output window the Graph Builder for this data table
TheVLB << append(
gb = dtstacked << Graph Builder(
Size( 542, 428 ),
Show Control Panel( 0 ),
Variables( X( :Chemical Compound ), Y( :Data ), Page( :Sample ) ),
Elements( Bar( X, Y, Legend( 6 ) ) ),
SendToReport(
Dispatch(
{},
"Chemical Compound",
ScaleBox( 2 ),
{Label Row( Label Orientation( "Angled" ) )}
),
Dispatch(
{},
"Data",
ScaleBox( 2 ),
{Min( 0 ), Inc( 0.02 ), Minor Ticks( 0 )}
),
Dispatch(
{},
"400",
ScaleBox,
{Legend Model( 6, Properties( 0, {Fill Color( 45 )} ) )}
),
Dispatch(
{},
"graph title",
TextEditBox,
{Set Text( "Product Sample" )}
),
Dispatch( {}, "X title", TextEditBox, {Set Text( "" )} ),
Dispatch( {}, "Y title", TextEditBox, {Set Text( "" )} ),
Dispatch( {}, "400", LegendBox, {Set Title( "" )} )
)
)
);

// Add reference lines every 2%
For( i = .02, i <= Report( gb )[AxisBox( 2 )] << get max, i = i + .02,
Report( gb )[AxisBox( 2 )] << Add Ref Line( i, "Solid", "Black", "", 1 );
);
// Adding reference lines changes the increment(JMP bug I think)
// so change the increment back to 2%
Report( gb )[AxisBox( 2 )] << inc( .02 );
);
),
// These are the items to substitute
Expr( __nw__ ), Parse( "nw" || TheRandom ),
Expr( __DataTableList__ ), Parse( "DataTableList" || TheRandom )
)
);
// Close dttemp data table since it is no longer needed
Close( dttemp, nosave );

Jim
Lharbicht

New Contributor

Joined:

Nov 15, 2016

Hi Jim,

 

Thank you for your help. I was hoping the solution was something a bit easier that I could do out of graph builder, but that's okay! I'm quite new to JMP and have not dealt with JSL at all yet, but I have done some work with VBA in excel so I'm sure I can figure it out.

 

Thanks again,

 

Lacey

txnelson

Super User

Joined:

Jun 22, 2012

Solution
Lacey,
Everything I did in the script, came from running interactively. In fact, the first example I gave could very easily be done interactively. Just take a look at the script, and you can see the steps it takes, and you can just mimic them interactively.
Jim