Data visualization with SAS programming

sgpanel time series plot spaghetti chart

Reply
Contributor
Posts: 40

sgpanel time series plot spaghetti chart

I'm trying to plot multiple time series plot which looks like a spahetti plot. I'm trying to avoid spaghetti plot by using lattice or panel like plots.

 

Here is the SAS dataset to replicate,I have dataset called "temp" with grouping variable called group. The data is time series with time variable "date" and y variable "air".

 

data alldata1;
		set sashelp.air;

		group = "REF";

		keep date air group;
run;

data alldata2;
		set sashelp.air;

		group = "A1";

		air=air+30;

		keep date air group;
run;

data alldata3;
		set sashelp.air;

		group = "A2";

		air=air+60;

		keep date air group;
run;

data alldata4;
		set sashelp.air;

		group = "A3";

		air=air-30;

		keep date air group;
run;

data alldata5;
		set sashelp.air;

		group = "A4";

		air=air-60;

		keep date air group;
run;

data temp;
		    set alldata1
			alldata2
			alldata3
			alldata4
			alldata5;

run;

The grouping variable "group" has 5 categories. "REF", A1,A2,A3,A4. I need to creat a chart like the one below where "REF" group highlighted in "red" and each category is highlighted in blue and the rest of the category in light grey.

 

spagetti.JPG

 

Below are my questions:

  1. How do I replicate thie above using a SAS procedure ?
  2. how can I choose the number of rows and columns, in the above chart it is 2 (rows) by 2 (colums). What if I have more than 8 categories and want to display it as ?
  3. how can I export this cart as ps or png high resolution file?

 

Thanks

Grand Advisor
Posts: 17,396

Re: sgpanel time series plot spaghetti chart

Some answers to help you get started. 

1. SGPLOT Series graph, use a BY statement for different graphs or SGPANEL, given sample SGPLOT looks easier.

2. Either PROC GREPLAY and ODS DOCUMENT to control the layout or output to a PDF file with columns=2. It doesn't matter how many categories exist if you use  a BY statement it will automatically create them all. 

3. Specify the device type under ODS GRAPHICS options statements. 

 

What SAS version do you have? The graphics options vary a bit in the last few. For example, AttributeMaps will allow you to control the colours the easiest and is in the later releases. 

 

 

Contributor
Posts: 40

Re: sgpanel time series plot spaghetti chart

I have SAS 9.4. Can you please show me how to use SAS sgplot? I have provided a reproducible example. I tried sgpanel but not sure how to use all series at once? Thanks
Valued Guide
Posts: 505

Re: sgpanel time series plot spaghetti chart

HAVE
====

Up to 40 obs from temp total obs=576

Obs    DATE     AIR    GROUP    AIR1

  1    JAN49    142     A1       112
  2    JAN49    172     A2       142
  3    JAN49    202     A3       172
  4    JAN49    232     A4       202
  5    FEB49    148     A1       118
  6    FEB49    178     A2       148
  7    FEB49    208     A3       178
  8    FEB49    238     A4       208
....
569    NOV60    420     A1       390
570    NOV60    450     A2       420
571    NOV60    480     A3       450
572    NOV60    510     A4       480
573    DEC60    462     A1       432
574    DEC60    492     A2       462
575    DEC60    522     A3       492
576    DEC60    552     A4       522

WANT ( see below)


FULL SOLUTION
=============

data have;
  set sashelp.air;
  do group="A1","A2","A3","A4";
       air1=air;
       air=air+30;
       output;
  end;
run;quit;

options orientation=landscape;
ods pdf file="d:/pdf/panel.pdf"  notoc;
title "Group Panels";
proc sgpanel data=temp;
panelby group / columns = 2 rows = 2;
series x=date y=air;
series x=date y=air1 ;
run;quit;

SGPanel19.png

Ask a Question
Discussion stats
  • 3 replies
  • 211 views
  • 0 likes
  • 3 in conversation