Data visualization with SAS programming

Mirrored plots in GTL

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 78
Accepted Solution

Mirrored plots in GTL

I'm trying to do something like Sanjay's vertical mirrored histograms, but with the overlays with 2 plots each.  No matter what I try, I can't get the x-axes to be on the same line; there is always a gap.  (See the attached pdf.)

Can anyone tell me what I'm doing wrong?

(Also, if you tell me how to reduce the whitespace to the right of the chart, I'd appreciate it.)

This is the template I wrote (using a picture of my code because cut/paste does not work):

Template.JPG


Accepted Solutions
Solution
‎11-11-2014 09:18 AM
SAS Super FREQ
Posts: 1,040

Re: Mirrored plots in GTL

Set the YAxisOpts=(LinearOpts=())  TickValueList or TickValueSequence option.  Remove needle baseline.

View solution in original post

Attachment

All Replies
SAS Super FREQ
Posts: 1,040

Re: Mirrored plots in GTL

Try setting YAXISOPTS=(Offsetmin=0);

Frequent Contributor
Posts: 78

Re: Mirrored plots in GTL

I added the option to each "layout overlay" statement, but it did not change the output at all.

SAS Super FREQ
Posts: 1,040

Re: Mirrored plots in GTL

Please attach full code with data to produce the graph.

Try removing the "0" ticks in both Y axes. Sometimes the lattice needs to allow space for half the text height to avoid collision.


Aside:    Could you make this using SGPLOT with negative and positive values for the needles?  Use a picture format to turn the -ive values to +ive, and maybe a Band plot to draw the blocks?

Frequent Contributor
Posts: 78

Re: Mirrored plots in GTL

(Still working on getting you a simplified code+data example.)

How does one remove a particular tick?  (I think I can figure out how to remove everything from the axis.)

As for the aside, that is my backup plan.  Since I remembered reading your "mirrored" post, I looked it up and started there.

Frequent Contributor
Posts: 78

Re: Mirrored plots in GTL

Attached is Sample.sas, a  self-contained example that exhibits the problem I'm hoping you can help me solve.

FYI, here's my configuration from the log file:

NOTE: SAS (r) Proprietary Software 9.3 (TS1M1)     

...

NOTE: This session is executing on the X64_7PRO  platform.

Thanks for the help!

Attachment
Solution
‎11-11-2014 09:18 AM
SAS Super FREQ
Posts: 1,040

Re: Mirrored plots in GTL

Set the YAxisOpts=(LinearOpts=())  TickValueList or TickValueSequence option.  Remove needle baseline.

Attachment
Frequent Contributor
Posts: 78

Re: Mirrored plots in GTL

>>>YAxisOpts=(LinearOpts=())

This did not help.

Setting yaxisopts=(display=none) did get the zeros to coincide, but I need the axis and the ticks.  But I think this means you're on to something w.r.t. labels needing space.

I'll try your other suggestions.

SAS Super FREQ
Posts: 1,040

Re: Mirrored plots in GTL

You have to put a TickValueList inside the LinearOpts bundle.  See the code and result I attached.

Frequent Contributor
Posts: 78

Re: Mirrored plots in GTL

My apologies; I didn't notice the attachments.  I ran SampleNew.sas and it looks good.  I'll have to detect the max y-value and use a macro to generate the list of tick labels, but that's in my wheelhouse.

I'm glad I don't have to use the backup plan (sgplot), because I'm not finished tweaking this layout.  For example, I'm probably going to top the needles that appear in the "blocked" region with a circle (using a series plot).

Any idea how to get the graph to fit the width of the page in the PDF?  The PNG file doesn't have extra space to the right of the graph?

SAS Super FREQ
Posts: 1,040

Re: Mirrored plots in GTL

You can set the TickValueSequence instead.  You don't need to know the exact data extent.  If you provide a sequence that exceeds the data, it will only use the part that is needed to cover the data.  You will need to determine the increment. That is why I think the SGPLOT version will be easier.

SAS Super FREQ
Posts: 1,040

Re: Mirrored plots in GTL

Here is the same graph with SG and code.  See attached zip file.  You just need to add the picture format to turn the negative values on the Y axis to positive.

Attachment
Frequent Contributor
Posts: 78

Re: Mirrored plots in GTL

That's great.  Thanks, Sanjay.  (At this point I'm not sure which version I prefer.)

SAS Employee
Posts: 963

Re: Mirrored plots in GTL

If you can't get it working the way you want with GTL, here's a way to do it with Proc Gplot...

data timeline; set timeline;

ab_count=-1*ab_count;

run;

data anno_top; set timeline;

by xy_blocked notsorted;

xsys='2'; ysys='2'; when='b';

if first.xy_blocked then do;

if xy_blocked='Y' then do;

  x=date; y=0; function='move'; output;

  end;

end;

if last.xy_blocked then do;

if xy_blocked='Y' then do;

  x=date; y=8; function='bar'; style='solid'; color='graydd'; output;

  end;

end;

run;

data anno_bottom; set timeline;

by ab_blocked notsorted;

xsys='2'; ysys='2'; when='b';

if first.ab_blocked then do;

if ab_blocked='Y' then do;

  x=date; y=0; function='move'; output;

  end;

end;

if last.ab_blocked then do;

if ab_blocked='Y' then do;

  x=date; y=-8; function='bar'; style='solid'; color='graydd'; output;

  end;

end;

run;

data anno_blocked; set anno_top anno_bottom;

run;

symbol1 value=none interpol=needle mode=include color=blue;

symbol2 value=none interpol=needle mode=include color=red;

axis1 label=(a=90 "Y-Bottom                         Y-Top")

order=(-8 to 8 by 2) minor=none offset=(0,0);

axis2 label=none order=('01jan2012'd to '01jan2015'd by year)

minor=none offset=(0,0);

proc format; picture posval low-high='000,009'; run;

title1 ls=1.5 "Mirrored Gplot";

proc gplot data=timeline anno=anno_blocked;

format date mmddyys10.;

format xy_count ab_count posval.;

plot xy_count*date=1 ab_count*date=2 / overlay

vaxis=axis1 haxis=axis2;

run;

mirror.png

Frequent Contributor
Posts: 78

Re: Mirrored plots in GTL

Thanks.  The only SAS graphing I've worked with so far is GTL, so there is much new to me in the gplot syntax.  I'm under time pressure (of course!), so your solution will have to be the backup to Sanjay's backup (of using a tricked SGPLOT rather than a lattice template).

Post a Question
Discussion Stats
  • 14 replies
  • 1131 views
  • 6 likes
  • 3 in conversation