BookmarkSubscribe
Choose Language Hide Translation Bar
pmroz
Super User

Bar and Errorbar Colors for Forest Plot?

I'm creating forest plots and have come up with two styles:

ForestPlots.png

I'm trying to control the color of the bars, points and error bars through row colors:

ForestData.png

My question is why aren't the solid bars and the error bars in the desired color?

dt = New Table( "Forest Plot", Add Rows( 5 ), 
	New Column( "EVENT_NAME", Character( 20 ), "Nominal",
		Set Values( {"AAAAAAA", "BBBBBBB", "CCCCCCC", "DDDDDDD", "EEEEEEE"} ) ),
	New Column( "DISPROP025", Numeric, "Continuous", Format( "Fixed Dec", 16, 2 ),
		Set Values(
			[5.3766744840813, 1.28687381477736, 5.96303490967794, 1.55531597890029, 2.34164191312678] ) ),
	New Column( "DISPROP", Numeric, "Continuous", Format( "Fixed Dec", 16, 2 ),
		Set Values(
			[5.76756983251198, 1.49287821887835, 7.02941951612351, 3.83591362397761, 2.62194430908125] ) ),
	New Column( "DISPROP975", Numeric, "Continuous", Format( "Fixed Dec", 16, 2 ),
		Set Values(
			[6.06935482201811, 1.66251397924122, 7.91895228410917, 6.92389142535734, 2.84619058478479] ) ),
	New Column( "Alert", Character, "Nominal",
		Formula( If( :DISPROP025 > 1 & :DISPROP > 2, "Y", "N" ) ) ),
	Set Row States( [13568, 13056, 13568, 13568, 13568] )
);

// Bars + central point
dt << Graph Builder(
	Show Control Panel( 0 ),
	Variables(
		X( :DISPROP025 ),
		X( :DISPROP, Position( 1 ) ),
		X( :DISPROP975, Position( 1 ) ),
		Y( :EVENT_NAME )
	),
	Elements(
		Bar( X( 1 ), X( 3 ), Y, Legend( 9 ), Bar Style( "Range" ) ),
		Points( X( 2 ), Y, Legend( 10 ), Jitter( 0 ) )
	),
	SendToReport(
		Dispatch( {}, "DISPROP025", ScaleBox,
			{Min( 0 ), Add Ref Line( 1, "Dotted", "Dark Red", "", 2 ),
			Label Row( Show Major Grid( 1 ) )}
		),
		Dispatch( {}, "EVENT_NAME", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
		Dispatch( {}, "X title", TextEditBox, {Set Text( "Disproportionality" )} ),
		Dispatch( {}, "Y title", TextEditBox, {Set Text( "PT" )} )
	)
);

// Error bars
dt << Graph Builder(
	Show Control Panel( 0 ),
	Variables(
		X( :DISPROP025 ),
		X( :DISPROP, Position( 1 ) ),
		X( :DISPROP975, Position( 1 ) ),
		Y( :EVENT_NAME )
	),
	Elements(
		Bar( X( 1 ), X( 3 ), Y, Legend( 9 ), Bar Style( "Interval" ) ),
		Points( X( 2 ), Y, Legend( 10 ), Jitter( 0 ) )
	),
	SendToReport(
		Dispatch( {}, "DISPROP025", ScaleBox,
			{Min( 0 ), Add Ref Line( 1, "Dotted", "Dark Red", "", 2 ),
			Label Row( Show Major Grid( 1 ) )}
		),
		Dispatch( {}, "EVENT_NAME", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
		Dispatch( {}, "X title", TextEditBox, {Set Text( "Disproportionality" )} ),
		Dispatch( {}, "Y title", TextEditBox, {Set Text( "PT" )} )
	)
);
0 Kudos
3 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Bar and Errorbar Colors for Forest Plot?

Hi,

 

Have you taken a look at Richard Zink's add-in on forest plots?

 

https://community.jmp.com/t5/JMP-Add-Ins/Forest-Plot-Add-In/ta-p/23977

 

Since the Add-in is esentially a zip file, you can rename the file extension to .zip and unzip it. There you can see his JSL and maybe use some of that.

 

Chris

Chris Kirchberg
Principal Systems Engineer, Life Sciences - JMP Global Technical Enablement
SAS Institute, Inc. - Denver, CO
Tel: +1-919-531-9927 ▪ Mobile: +1-303-378-7419 ▪ E-mail: chris.kirchberg@jmp.com
JMP – A Division of SAS Institute | www.jmp.com

Re: Bar and Errorbar Colors for Forest Plot?

Wait, I found a way. If you open the control panel and go to the section the says bar at the bottom, there will be a varialbe section. Open it and check all variables. a point will appear where you want it. Remove the points element from teh graph. Then use Alert variable for overlay.

 

So the script would look something like this


Graph Builder(
	Size( 606, 564 ),
	Variables(
		X( :DISPROP025 ),
		X( :DISPROP, Position( 1 ) ),
		X( :DISPROP975, Position( 1 ) ),
		Y( :EVENT_NAME ),
		Overlay( :Alert )
	),
	Elements(
		Bar( X( 1 ), X( 3 ), X( 2 ), Y, Legend( 9 ), Bar Style( "Interval" ) )
	),
	SendToReport(
		Dispatch(
			{},
			"DISPROP025",
			ScaleBox,
			{Add Ref Line( 1, "Dotted", "Dark Red", "", 2 ),
			Label Row( Show Major Grid( 1 ) )}
		),
		Dispatch( {}, "EVENT_NAME", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				9,
				Properties( 0, {Line Color( 6 )} ),
				Properties( 1, {Marker( "Dot" )} ),
				Properties( 2, {Line Color( -5682409 )} ),
				Properties( 3, {Marker( "Dot" )} )
			)}
		),
		Dispatch( {}, "X title", TextEditBox, {Set Text( "Disproportionality" )} ),
		Dispatch( {}, "Y title", TextEditBox, {Set Text( "PT" )} )
	)
);
Chris Kirchberg
Principal Systems Engineer, Life Sciences - JMP Global Technical Enablement
SAS Institute, Inc. - Denver, CO
Tel: +1-919-531-9927 ▪ Mobile: +1-303-378-7419 ▪ E-mail: chris.kirchberg@jmp.com
JMP – A Division of SAS Institute | www.jmp.com

Re: Bar and Errorbar Colors for Forest Plot?

Well, darn it.  Another way is to stack the DISPROP columns into one and make the value column (called data in the below script) continuous. Then use this script


Graph Builder(
	Size( 992, 630 ),
	Show Control Panel( 0 ),
	Variables( X( :Data ), Y( :EVENT_NAME ), Overlay( :Alert ) ),
	Elements(
		Points(
			X,
			Y,
			Legend( 5 ),
			Jitter( 0 ),
			Summary Statistic( "Median" ),
			Error Bars( "Range" )
		)
	),
	SendToReport(
		Dispatch( {}, "Data", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
		Dispatch( {}, "EVENT_NAME", ScaleBox, {Label Row( Show Major Grid( 1 ) )} )
	)
);

image.png

Its close, but there is still somthing a little off about the grid line and the data points using overlay

Chris Kirchberg
Principal Systems Engineer, Life Sciences - JMP Global Technical Enablement
SAS Institute, Inc. - Denver, CO
Tel: +1-919-531-9927 ▪ Mobile: +1-303-378-7419 ▪ E-mail: chris.kirchberg@jmp.com
JMP – A Division of SAS Institute | www.jmp.com
9 REPLIES 9

Re: Bar and Errorbar Colors for Forest Plot?

Hi,

 

Have you taken a look at Richard Zink's add-in on forest plots?

 

https://community.jmp.com/t5/JMP-Add-Ins/Forest-Plot-Add-In/ta-p/23977

 

Since the Add-in is esentially a zip file, you can rename the file extension to .zip and unzip it. There you can see his JSL and maybe use some of that.

 

Chris

Chris Kirchberg
Principal Systems Engineer, Life Sciences - JMP Global Technical Enablement
SAS Institute, Inc. - Denver, CO
Tel: +1-919-531-9927 ▪ Mobile: +1-303-378-7419 ▪ E-mail: chris.kirchberg@jmp.com
JMP – A Division of SAS Institute | www.jmp.com

Re: Bar and Errorbar Colors for Forest Plot?

You might have to use the Alert variable to color. This works on the bar graph but not the error bar graph.The Error Bar color is controlled by the legend color. Not sure how to script different colors for different error bars.
Chris Kirchberg
Principal Systems Engineer, Life Sciences - JMP Global Technical Enablement
SAS Institute, Inc. - Denver, CO
Tel: +1-919-531-9927 ▪ Mobile: +1-303-378-7419 ▪ E-mail: chris.kirchberg@jmp.com
JMP – A Division of SAS Institute | www.jmp.com
0 Kudos

Re: Bar and Errorbar Colors for Forest Plot?

Wait, I found a way. If you open the control panel and go to the section the says bar at the bottom, there will be a varialbe section. Open it and check all variables. a point will appear where you want it. Remove the points element from teh graph. Then use Alert variable for overlay.

 

So the script would look something like this


Graph Builder(
	Size( 606, 564 ),
	Variables(
		X( :DISPROP025 ),
		X( :DISPROP, Position( 1 ) ),
		X( :DISPROP975, Position( 1 ) ),
		Y( :EVENT_NAME ),
		Overlay( :Alert )
	),
	Elements(
		Bar( X( 1 ), X( 3 ), X( 2 ), Y, Legend( 9 ), Bar Style( "Interval" ) )
	),
	SendToReport(
		Dispatch(
			{},
			"DISPROP025",
			ScaleBox,
			{Add Ref Line( 1, "Dotted", "Dark Red", "", 2 ),
			Label Row( Show Major Grid( 1 ) )}
		),
		Dispatch( {}, "EVENT_NAME", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				9,
				Properties( 0, {Line Color( 6 )} ),
				Properties( 1, {Marker( "Dot" )} ),
				Properties( 2, {Line Color( -5682409 )} ),
				Properties( 3, {Marker( "Dot" )} )
			)}
		),
		Dispatch( {}, "X title", TextEditBox, {Set Text( "Disproportionality" )} ),
		Dispatch( {}, "Y title", TextEditBox, {Set Text( "PT" )} )
	)
);
Chris Kirchberg
Principal Systems Engineer, Life Sciences - JMP Global Technical Enablement
SAS Institute, Inc. - Denver, CO
Tel: +1-919-531-9927 ▪ Mobile: +1-303-378-7419 ▪ E-mail: chris.kirchberg@jmp.com
JMP – A Division of SAS Institute | www.jmp.com
pmroz
Super User

Re: Bar and Errorbar Colors for Forest Plot?

Thanks Chris.  I did a search for Forest Plots and Richard's very nice addin didn't show up.  I like your coding solution as well.

0 Kudos
pmroz
Super User

Re: Bar and Errorbar Colors for Forest Plot?

One more puzzler - when I drag my Alert column into the Overlay role I can control the colors nicely.  However the points are on the horizontal lines but the error bars aren't.  Any way to correct this?  If I drag Alert onto the Color role there is no "jitter", but then I can't set the color of the error bars.

ForestPlot2.png

0 Kudos

Re: Bar and Errorbar Colors for Forest Plot?

The Key to using overlay is to not have the Points graph element added. Click on the Points Icont at the top to turn it off. Then Bar options/discolsure box at the bottom left, put a check next to the variable DISPROP. Points will not be added inline with the error bar.

Chris Kirchberg
Principal Systems Engineer, Life Sciences - JMP Global Technical Enablement
SAS Institute, Inc. - Denver, CO
Tel: +1-919-531-9927 ▪ Mobile: +1-303-378-7419 ▪ E-mail: chris.kirchberg@jmp.com
JMP – A Division of SAS Institute | www.jmp.com
pmroz
Super User

Re: Bar and Errorbar Colors for Forest Plot?

Still no joy.  It appears that when there is a mix of Y and N alerts, the error bars are offset from the gridlines.

Forest Plot.png

Here's the code:


Graph Builder(
	Size( 726, 451 ),
	Show Control Panel( 0 ),
	Show Legend( 0 ),
	Variables(
		X( :DISPROP025 ),
		X( :DISPROP975, Position( 1 ) ),
		X( :DISPROP, Position( 1 ) ),
		Y( :EVENT_NAME ),
		Overlay( :Alert )
	),
	Elements(
		Bar( X( 1 ), X( 2 ), X( 3 ), Y, Legend( 8 ), Bar Style( "Interval" ) )
	),
	SendToReport(
		Dispatch( {}, "DISPROP025", ScaleBox,
			{Min( 0 ), Add Ref Line( 1, "Dotted", "Dark Red", "", 1 ),
			Label Row( Show Major Grid( 1 ) )}
		),
		Dispatch( {}, "EVENT_NAME", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
		Dispatch( {}, "400", ScaleBox,
			{Legend Model(
				8,
				Properties( 0, {Line Color( 51 ), Line Width( 2 )} ),
				Properties( 1, {Line Color( 51 ), Marker( "FilledCircle" )} ),
				Properties( 2, {Line Color( 53 ), Line Width( 2 )} ),
				Properties( 3, {Line Color( 53 ), Marker( "FilledCircle" )} )
			)}
		)
	)
);
0 Kudos

Re: Bar and Errorbar Colors for Forest Plot?

Well, darn it.  Another way is to stack the DISPROP columns into one and make the value column (called data in the below script) continuous. Then use this script


Graph Builder(
	Size( 992, 630 ),
	Show Control Panel( 0 ),
	Variables( X( :Data ), Y( :EVENT_NAME ), Overlay( :Alert ) ),
	Elements(
		Points(
			X,
			Y,
			Legend( 5 ),
			Jitter( 0 ),
			Summary Statistic( "Median" ),
			Error Bars( "Range" )
		)
	),
	SendToReport(
		Dispatch( {}, "Data", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
		Dispatch( {}, "EVENT_NAME", ScaleBox, {Label Row( Show Major Grid( 1 ) )} )
	)
);

image.png

Its close, but there is still somthing a little off about the grid line and the data points using overlay

Chris Kirchberg
Principal Systems Engineer, Life Sciences - JMP Global Technical Enablement
SAS Institute, Inc. - Denver, CO
Tel: +1-919-531-9927 ▪ Mobile: +1-303-378-7419 ▪ E-mail: chris.kirchberg@jmp.com
JMP – A Division of SAS Institute | www.jmp.com
pmroz
Super User

Re: Bar and Errorbar Colors for Forest Plot?

That is a clever solution that is "close enough for government work".  I thickened the lines to a width of 2 and the slight offset is not noticeable.  Thanks Chris!

0 Kudos