I'm attempting to create a contour plot (proc gcontour) that uses a gradient of colors -- ideally, dark blue, through to, red. Dark blue would show the lowest of values. Red, the highest.
So far I can think only of listing all colors that I'd like to use, via goptions, colors=().
The colors would likely have to be in hexadecimal format (CXFF0000, etc.).
If I want to show 20 levels on the contour plot, I'd have to come up with a 20-member list in hexadecimal format. Somehow uniformly spaced throughout the range.
Would be really nice if SAS can automatically generate such a gradient for a contour plot.
Am I simply missing it?
Sure hope so.
Please advise.
Nicholas Kormanik
You can use the PALETTE function in SAS/IML to create custom color ramps.
If you switch from PROC GCONTOUR and instead
define a contour plot by using the GTL template and the CONTOURPLOTPARM statement, then you can use the COLORMODEL= option to define a color ramp. You can use the syntax COLORMODEL=(blue red) to define a two-color ramp that linearly interpolates between blue and red. Or you can use the built-in COLORMODEL=ThreeColorRamp to use a three-color ramp that goes from blue (low) to white (neutral) to red (high).
You can use the PALETTE function in SAS/IML to create custom color ramps.
If you switch from PROC GCONTOUR and instead
define a contour plot by using the GTL template and the CONTOURPLOTPARM statement, then you can use the COLORMODEL= option to define a color ramp. You can use the syntax COLORMODEL=(blue red) to define a two-color ramp that linearly interpolates between blue and red. Or you can use the built-in COLORMODEL=ThreeColorRamp to use a three-color ramp that goes from blue (low) to white (neutral) to red (high).
Thank you, Rick. Really appreciate you being available here to help. As well as all the others. Amazing community.
Nicholas
The COLORMODEL= option is supported in GTL and in the SG procedures, but not (as far as I know) in the GCONTOUR procedure. The GCONTOUR procedure uses a different syntax, which I am not very familiar with because I started learning SAS graphics when the SG (statistical graphics) procedures were being developed. I'll leave it to others to suggest ways to solve your problem by using PROC GCONTOUR.
If you want to continue to use PROC GCONTOUR, but have gradient colors, I think you best option is to go to to the color brewer site, select the pallette and number of levels you want, and put those colors in your GOPTIONS COLORS= option. Here is the URL for the site: http://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3
Hope this helps!
Dan
Terrific site, Dan. Will do that for now, just add colors in goptions.
But will have to learn the SG procedures as well, as Rick suggests.
Thanks for your help.
Beautiful....
Just for completeness, I'll mention that the color list could also be specified on the CLEVELS option instead of the GOPTIONS COLORS= option. That way, the colors would not affect any other SAS/Graph plots or force you to do a GOPTIONS RESET=ALL before generating the next plot.
Thanks!
Dan
One more question....
I vaguely recollect that SAS holds somewhere -- at least temporarily -- nearly every aspect of the output of all procedures. Sort of hidden away. That if you want to extract/save any of this, it's possible. If you just know where exactly to find it.
So, in the contour plot above, at bottom, is the legend, specifying the contour levels.
I would like to save that data vector, in .sas7bdat, or in .txt, etc., format. And give the extracted/saved file a name -- i.e., "contour_levels_xyz.sas7bdat".
Any continuing help greatly appreciated.
You might be thinking about using ODS OUTPUT to save tables into data sets. You can also use ODS OUTPUT to output the data values on the ODS statistical graphics that are created from SAS procedures or from .... That is one of the advantages to using ODS GRAPHICS: all output goes through ODS which means you can select it, store it, send it to various destinations, etc.
Thanks, Rick. Great lead.
Unfortunately in the present case only output is the original input data set. No sign at all of the vector of numbers used for the contour divisions.
Perhaps this is an additional reason to move on to SG, GTL, IML, whatever. Maybe one of these can produce a contour map with savable contour divisions.
If anyone wants to help get there.....
Do you know (or can you determine) the maximum and minimum value of the surface on the rectangular domain that you are plotting?
If so, you can determine the contour levels.
Contours are determined by evenly spaced subdivisions in the range of the Z value of the data. So if you want M contours then they are positions at
z = Zmin + k*dz, for k=1, 2, 3, ..., M
and dz = (ZMax = ZMin) / (M+1)
where ZMin = min(z on rectangular domain) and ZMax = max(z on rectangular domain).
For example, in your picture, it looks like
ZMin ~ -20.5
ZMax ~ 21.6
and you have M=18 contours so
dz = (21.6 - (-20.5) / 19= 2.216 and the contours are at the heights
z1 = -20.5 + 2.216;
z2 = -20.5 + 2* 2.216;
...
data Levels;
zMax = 21.6; /* max of surface on rectangle */
zMin = -20.5;
M = 18; /* number of contours */
dz = (zMax - zMin) / (M+1);
do i = 1 to M;
z = zMin + i*dz;
output;
end;
run;
proc print data=levels;
var i z;
run;
Beautifully shown, Rick. Good for my own understanding and reference, as well as useful for others. Thanks!
Do you know (or can you determine) the maximum and minimum value of the surface on the rectangular domain that you are plotting?
Well, I was hoping that the contour process itself would give me those values. I have hundreds of such data sets to examine. If I could have extracted contour vectors for each one, I was then hoping to cluster-analyze them. Without the data I will simply have to eyeball the graphs, to try to make sense somehow.
At any rate, I may have been overestimating the value of capturing those contour values. May be better to proceed on to other avenues.
The objective, though, is to study 3D representations of data sets. Will presently turn to proc loess, proc kde, proc krige2d, etc.
Of these, are you particularly keen on one versus another?
All comments welcome.
I have some experience with those procedures. They do different things:
1) LOESS assumes that Z (the response) is a nonparametric of (X, Y). Local weighted regression is used to predict Z.
2) KDE is quite different. It estimates the density of (X, Y). It does not predict a third variable, Z.
3) KRIGE2D is a spatial analysis procedure. You should use it only if your (X, Y) data represent coordinates (spatial locations) in some field or forest.
There are other procedures such as PROC GLMMIX and PROC GAMPL that can model responses by using parametric or nonparametric models.
Which procedure I would recommend depends on what you are trying to accomplish. I do not know what you mean by " 3D representations of data sets." Do you have a reference, or can you describe the business use for the analysis?
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!
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.