Data visualization with SAS programming

Text rows uneven in forest plot

Reply
Contributor VCM
Contributor
Posts: 21

Text rows uneven in forest plot

I'm working on a forest plot with several columns of associated data.  The alignment is slightly off:

 

HR.png

 

Note that in the first row, the p-val is slightly lower than the HR/CI.  By the last row, the p-val sits higher than the HR/CI.

 

Code for the text columns from proc template:

 

layout overlay / xaxisopts=(display=none) 
yaxisopts=(reverse=true display=none) walldisplay=none;
scatterplot x=dummy y=ord / markercharacter=hr_ci;
endlayout; *** overlay - Hazard Ratio/CI column***;

layout overlay / xaxisopts=(display=none) 
yaxisopts=(reverse=true display=none) walldisplay=none;
scatterplot x=dummy y=ord / markercharacter=pval;
endlayout; *** overlay - p-value column ***;

Dummy is, as the name implies, a dummy value (= 1 for every record).  Ord is the numeric order of the rows.  The markercharacters hr_ci and pval are the character results you see above.

 

Is there any way to "straighten out" the row alignment?

SAS Super FREQ
Posts: 496

Re: Text rows uneven in forest plot

Use axis tables.  There are many example of forest plots in the graphically speaking blog.

 

https://blogs.sas.com/content/graphicallyspeaking/

Contributor
Posts: 29

Re: Text rows uneven in forest plot

I have always used annotate for that: http://documentation.sas.com/?docsetId=grstatgraph&docsetTarget=p0fnr3r0fc0jfjn1rtp6di3ygpom.htm&doc...

it can be a bit fidgety but you get things exactly where you want them

Contributor VCM
Contributor
Posts: 21

Re: Text rows uneven in forest plot

Thanks, everyone--I was out yesterday so one of our plot gurus was called in to look at it.  Her solution:  make the dots smaller.  The size was knocking everything else out of whack.

 

But you have given me a lot of food for thought if I ever run into a similar situation where dot size doesn't help. Smiley Happy

SAS Super FREQ
Posts: 496

Re: Text rows uneven in forest plot

I'm glad you got it worked out. If you don't switch to use axis tables, next time at least look into the TEXT statement (unless you are using a release from before it came out) as an alternative to SCATTER.

SAS Super FREQ
Posts: 1,261

Re: Text rows uneven in forest plot

[ Edited ]
Posted in reply to WarrenKuhfeld

Just an FYI...The three separate scatter statements cause different y-offsets due to size of markers and text.  As you increase marker size or text size), offsets increase, causing the alignment problems in different containers (Layout Overlays).  Each container with separate axes will have separate offsets based on their individual contents. 

 

One way to overcome this is to set fixed offsets on all containers (yaxisopts=(offsetmin=0.05 offsetmax=0.05).  Or, use common row axes to force all offsets to be the same.  This will also happen with TEXT plot or AXISTABLE.  One way to avoid this is to use only ONE Layout Overlay, and put the axis tables in the INNERMARGIN.

 

Your use case may be simple enough that you can use SGPLOT with a YAXISTABLE of two columns on the right side.  GTL may not be required.  See example here:  https://blogs.sas.com/content/graphicallyspeaking/2016/05/30/ctspedia-clinical-graphs-subgrouped-for....  Note the use of two yAxisTables on the left and one yAxisTable on the right with 3 variables.

 

Ask a Question
Discussion stats
  • 5 replies
  • 170 views
  • 0 likes
  • 4 in conversation