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:
Date | Rate | forecast_rate |
12/31/2012 | 1.72 | _10YrTr |
12/31/2013 | 1.3 | _10YrTr |
12/31/2014 | 1.8 | _10YrTr |
12/31/2015 | 2.3 | _10YrTr |
12/31/2012 | 0.07 | _3MoTr |
12/31/2013 | 0.1 | _3MoTr |
12/31/2014 | 0.1 | _3MoTr |
12/31/2015 | 0.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!
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
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
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?
What version of SAS do you have?
9.2 -- Sorry I didn't mention this initially.
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
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!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.