Data visualization with SAS programming

X Axis help for GPLOT - order and position

Reply
Frequent Contributor
Posts: 91

X Axis help for GPLOT - order and position

SAS folks-

I need your advice and help again. I have a graphics program that runs on a timed batch, gets the available data for the last 5 years, and then generates plots of variables over time.

I am using GPLOT so that I can control the output file names as name=parameter_location (location is byval) so that my project folks can find individual graphics easily by parameter in the output directory, and the output html file groups the graphics by location.  The locations, WQ parameters, and timeframe all change on a fairly regular basis.  

First problem:

Some of the locations have been recently discontinued, others have only existed for a few months, and some have everything, which results in different X axes.  I would like all of the X axes to be consistent, so the AXIS statement needs an ORDER= (UNIFORM does not work, as the Y axes must be different).

Currently, I am calculating the first date in the dataset, and from that, the first month (&MO).  I then use today() for the last date, and MONTH6.&MO for the increment as labels twice a year work out nicely on the graph.

I get nasty messages, but I do get all the data values.  Some data can start to come back in just a few days, so the end of the time period needs to be the date the program is run, not the beginning of the month it was run.

 

WARNING: The intervals on the axis labeled Date are not evenly spaced.

WARNING: No minor tick marks will be drawn because major tick increments have

         been specified in uneven or unordered intervals.

WARNING: The intervals on the axis labeled Date are not evenly spaced.

I have fooled with various values for interval (like SEMIYEAR), and have not come up with anything better.  What I would really like is to have a tick for every month, and a label twice a year. 

Even better if both the beginning and end can be calculated off the today() function somehow, rather than getting the first date from the data (I’m trying to think ahead).

Second problem (more of a pain than a problem, really):

To combine the legend for PLOT and PLOT2 statements, I had to plot the first Y variable twice, and reverse the ticks in the legend, which is a bit of a pain.  Because of the double call, it messes up the order of the colors, requiring the ticks to be reversed (no big deal, but irritating).   Then, on subsequent graphs, the plot area is larger, and the label for the X axis and the footnotes overlap.  

The following code is just a little subset, but has an example of both types of graphs – multiple parameters on same Y axis, and parameters on Y and Y2 axes.  I will try to attach some of the graphics, so you can see what the overlapping looks like.

Thanks for any help you can give me!

Wendy T

*set up output directory ;

%LET OUTDIR=&data_dump/provisional_final_graphics ;

*delete all files from output directory ;

systask command "del ""&outdir\*.* "" ";

*delete all existing graphics from WORK.GSEG ;

%INCLUDE &DEL_GSEG ; RUN ;

ODS LISTING CLOSE ;

FILENAME ODSOUT "&outdir" ;

ODS HTML FILE='provisional_final_graphics.html' PATH=ODSOUT ;

GOPTIONS DEVICE=GIF RESET=SYMBOL RESET=AXIS ;

DATA GRAPH1; SET WQ_DATA  ;

title ;

footnote1 'Last 5 years of WQ data';

WHERE STATION IN('ABC', 'DEF', 'GHI') AND

       SASDATE > (TODAY()- (365*5) )      ;

FORMAT SASDATE MMYYS5. ;

PROC SORT ; BY STATION ;

RUN ;

PROC MEANS MIN NOPRINT DATA=GRAPH1 ;

VAR SASDATE ;

OUTPUT OUT=DATER MIN=MINDATE ;

DATA _NULL_ ;  SET DATER ;

%LET ENDDATE=%SYSFUNC(TODAY(),DATE7.) ;

CALL SYMPUT('MINDATE',PUT(MINDATE,DATE7.)) ;

CALL SYMPUT('MO',PUT(MINDATE,MONTH1.)) ;

RUN ;

DATA GRAPH2; SET GRAPH1;

axis1  COLOR=BLACK LABEL=(COLOR=BLACK 'DATE') ORDER=("&MINDATE"D TO "&ENDDATE"D BY MONTH6.&MO) width=2.0 OFFSET=(2,2) ;

axis3  COLOR=BLACK LABEL=(COLOR=BLACK ANGLE=90  'Nitrogen (mg/L)')    width=2.0 OFFSET=(2,2) ;

axis6  COLOR=BLACK LABEL=(COLOR=BLACK ANGLE=90  'Chlorophyll (ug/L)') width=2.0 OFFSET=(2,2) ;

axis11 COLOR=BLACK LABEL=(COLOR=BLACK ANGLE=-90 'Secchi (m)')         width=2.0 OFFSET=(2,2) ;

SYMBOL1 VALUE=DOT     CV=BLACK     INTERPOL=STD1BJ CO=BLACK     CI=BLACK     LINE=1 ;

SYMBOL2 VALUE=DOT     CV=BLUE      INTERPOL=STD1BJ CO=BLUE      CI=BLUE      LINE=1 ;

SYMBOL3 VALUE=DOT     CV=RED       INTERPOL=STD1BJ CO=RED       CI=RED       LINE=1 ;

SYMBOL4 VALUE=DOT     CV=TURQUOISE INTERPOL=STD1BJ CO=TURQUOISE CI=TURQUOISE LINE=1 ;

proc gplot GOUT=WORK.GSEG ;

*TITLE #BYVAL(STATION) ;

   by STATION;

legend2 label=none frame down=2 position=(inside right top)  mode=share  value=

(tick=1 'TKN-T' tick=2 'TKN-D' tick=3 'NOX-D' tick=4 'NH4-D') ;

PLOT ( TKNT TKND NOXD NH4D )*SASDATE /OVERLAY LEGEND=legend2 FRAME HAXIS=AXIS1 VAXIS=AXIS3 NAME= 'NITROGEN_#BYVAL(STATION)' HREF='01AUG2009'D HREF='01MAR2010'D HREF='01OCT2011'D ;

* combined legend requires a double on the first graphic ;

* and the legend resets the first tick value on the PLOT2 statement ;

legend5 label=none frame down=2 position=(inside right top)  mode=share  value=

(tick=1 'SECCHI' tick=2 'CHL-A') ;

PLOT  (CHLA CHLA)*SASDATE   /OVERLAY LEGEND=legend5  FRAME HAXIS=AXIS1 VAXIS=AXIS6 NAME= 'CHLOROPHYLL_#BYVAL(STATION)' HREF='01AUG2009'D HREF='01MAR2010'D HREF='01OCT2011'D ;

PLOT2 (SECCHI)*SASDATE      /        LEGEND=legend5           VREVERSE VAXIS=AXIS11 ;

RUN;

QUIT;

ODS HTML CLOSE ;

ODS LISTING ;

*clean up ;

%SYMDEL outdir ;

TITLE ;

FOOTNOTE ;

RUN ;

Attachment
Attachment
Attachment
Attachment
Ask a Question
Discussion stats
  • 0 replies
  • 648 views
  • 0 likes
  • 1 in conversation