BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jdmarino
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

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

View solution in original post

14 REPLIES 14
Jay54
Meteorite | Level 14

Try setting YAXISOPTS=(Offsetmin=0);

jdmarino
Fluorite | Level 6

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

Jay54
Meteorite | Level 14

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?

jdmarino
Fluorite | Level 6

(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.

jdmarino
Fluorite | Level 6

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!

Jay54
Meteorite | Level 14

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

jdmarino
Fluorite | Level 6

>>>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.

Jay54
Meteorite | Level 14

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

jdmarino
Fluorite | Level 6

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?

Jay54
Meteorite | Level 14

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.

Jay54
Meteorite | Level 14

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.

jdmarino
Fluorite | Level 6

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

GraphGuy
Meteorite | Level 14

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

jdmarino
Fluorite | Level 6

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).

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 14 replies
  • 5014 views
  • 6 likes
  • 3 in conversation