BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hi

I produce 2 plots, one is a line contour plot produced with gcontour of a density computed from kde and the second a scatter plot of the original data produced with gplot. Does anyone know how the line contour plot can be overlayed on the scatter plot. ODS appears to be able to overlay
a scatter plot on a filled contour plot but this is not what I want.

My version of SAS is 9.1.3

Cheers
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
By default, in SAS 9.1.3, if you use ODS Graphics, it looks like you get a FILLed contour plot with a scatter overlaid on top of it. However, you CAN get a LINE contour plot with a scatter overlaid on it, by changing the DISPLAY=FILL in the graph template to DISPLAY=LINE for the CONTOURPLOTPARM statement:
[pre]
ContourPlotParm x=DENSITYX y=DENSITYY z=DENSITYCOUNT /
display=line nhint=15 name="Contour";

[/pre]

I don't see an overlay option in the PLOT statement of Proc GCONTOUR, so I'm not sure you'd be able to do what you want with PROC GPLOT/PROC GCONTOUR.

Perhaps the program below will give you an idea of what's possible with ODS Graphics in SAS 9.1.3 and will give you something to look forward to in SAS 9.2....I haven't investigated a lot, so I don't know whether the new SGPLOT/SGSCATTER will allow you to accomplish what you want (but I suspect it might).

Until then, perhaps some form of the program below will help. For more information on using Graph Templates with SAS 9.1.3, refer to this paper:
http://www2.sas.com/proceedings/sugi30/239-30.pdf
(Also, please note that this paper uses 9.1.3 specific syntax. With the new "statgraph" procedures available in SAS 9.2, changes to the graph template will probably NOT be needed.)

cynthia
[pre]
*** the program;
ods path work.tmp(update)
sashelp.tmplmst(read);

proc template;
define statgraph Stat.KDE.Graphics.ContourScatter;
dynamic _SCATTER _TITLE _DEPLABEL _DEPLABEL2;
layout Gridded;
layout overlay / padbottom=5;
entrytitle _TITLE;
endlayout;
layout lattice / rows=1 columns=1;
layout Overlay / xaxisopts=( thresholdmin=0 thresholdmax=0 )
yaxisopts=( thresholdmin=0 thresholdmax=0 ) xoffsetmin=0
xoffsetmax=0 yoffsetmin=0 yoffsetmax=0 padright=5;
ContourPlotParm x=DENSITYX y=DENSITYY z=DENSITYCOUNT /
display=line nhint=15 name="Contour";
if (_SCATTER=1)
scatterplot x=X y=Y /
markersymbol=GraphDataDefault:markersymbol
markercolor=GraphDataDefault:contrastcolor
markersize=GraphDataDefault:markersize;
endif;
EndLayout;
row2header;
GradientLegend "Contour";
endrow2header;
EndLayout;
EndLayout;
end;
run;


ods html path='.' (url=none)
file='kde_graf.html' style=analysis;
ods graphics on;
ods select contourscatter;
proc kde data=sashelp.class;
bivar age height / plots=all;
run;

ods graphics off;
ods html close;
[/pre]
deleted_user
Not applicable
Thanks Cynthia

I think I can get kind of what I want from this code. But is there a way to set the contour levels
explicitly as in gcontour where you can use the levels option.

Cheers
Cynthia_sas
SAS Super FREQ
Hi:
You might look at the documentation for the CONTOURPLOTPARM statement. For SAS 9.2, that is:
http://support.sas.com/rnd/base/topics/statgraph/proctemplate/a002650850.htm

It looks like the NHINTS and NLEVELS options control the suggested number of contour levels and the actual number of contour levels. For more help with Graph Templates, you might consider contacting Tech Support, as they know or can find out what or how the syntax worked between SAS 9.1.3 and SAS 9.2.

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 876 views
  • 0 likes
  • 2 in conversation