Data visualization with SAS programming

proc sgplot - scatter question

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 105
Accepted Solution

proc sgplot - scatter question

Hey guys,

I was wondering if it is possible to adjust the color of the 'markers' for each grouping:

essentially my data looks as follows:

DateRateforecast_rate
12/31/20121.72_10YrTr
12/31/20131.3_10YrTr
12/31/20141.8_10YrTr
12/31/20152.3_10YrTr
12/31/20120.07_3MoTr
12/31/20130.1_3MoTr
12/31/20140.1_3MoTr
12/31/20150.1_3MoTr

I would like to plot it as follows:

proc sgplot data=endyear_givens2;

  scatter x=forecast_Rate y=rate / group=date;

  run;

This gives me almost exactly what I need: the labels "_10YrTr" and "_3MoTr" on the x-axis with the numbers values labeled on the y axis, and the legend contains dates by marker shape. What I would like that is missing though, is for each year (each marker) to have a separate color, I can't figure out how to do this - if I use the markatts(color=) option it changes all 8 markers' colors, I want to see each year group (so both _3MoTr and _10YrTr markers will be one color for 12/31/2012, and then both _3MoTr and _10YrTr markers will be a different color for 12?31/2013, etc.) - Is This possible?

(I've attached the current sgplot output to perhaps be more clear)

Thank you!


Accepted Solutions
Solution
‎10-03-2013 04:40 PM
SAS Super FREQ
Posts: 864

Re: proc sgplot - scatter question

In SAS 9.3, this would be trivial. In that release we introduced "attribute map" data sets, where you can associate group values with visual attributes. You can use that data set with SGPLOT, SGPANEL, or SGSCATTER to do exactly what you describe above. To simulate this feature in SAS 9.2, you will need to use a GTL template, and use the INDEX option on the SCATTERPLOT statement to associate a style index to your group values. Then, create a column in your data that you will assign the values 1-N based on your group value. Use this column on the INDEX option in your template. If you need, I can put together an example of this. Just let me know.

Thanks!

Dan

View solution in original post


All Replies
SAS Super FREQ
Posts: 864

Re: proc sgplot - scatter question

Normally, the GROUP option affects both the shape and the color of the marker. It appears like the style you're using is giving you this behavior. Try this before your SGPLOT statement and see what you get:

ods html style=listing;

Let me know if that fixes the problem.

Thanks!

Dan

Frequent Contributor
Posts: 105

Re: proc sgplot - scatter question

Thank you for your helpful answer! That gets me halfway there -- They are in different color now which is good, but I still have no way of setting which group gets which color -- I want to manually set the color because I want each point to correspond to other graphs representing data by similar groupings, as it draws attention to a relationship that is bein portrayed in a presentation. Is this possible?

SAS Super FREQ
Posts: 864

Re: proc sgplot - scatter question

What version of SAS do you have?

Frequent Contributor
Posts: 105

Re: proc sgplot - scatter question

9.2 -- Sorry I didn't mention this initially.

Solution
‎10-03-2013 04:40 PM
SAS Super FREQ
Posts: 864

Re: proc sgplot - scatter question

In SAS 9.3, this would be trivial. In that release we introduced "attribute map" data sets, where you can associate group values with visual attributes. You can use that data set with SGPLOT, SGPANEL, or SGSCATTER to do exactly what you describe above. To simulate this feature in SAS 9.2, you will need to use a GTL template, and use the INDEX option on the SCATTERPLOT statement to associate a style index to your group values. Then, create a column in your data that you will assign the values 1-N based on your group value. Use this column on the INDEX option in your template. If you need, I can put together an example of this. Just let me know.

Thanks!

Dan

Frequent Contributor
Posts: 105

Re: proc sgplot - scatter question

Very interesting...an example won't be necessary, this information is extremely useful and I will be able to take it from here.

Thank you so much!

Post a Question
Discussion Stats
  • 6 replies
  • 539 views
  • 3 likes
  • 2 in conversation