Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scatter plot with gradient for 3rd dimension...

Status
Not open for further replies.

nobyrnes

Programmer
Mar 20, 2007
15
IE
Hey,
I am looking to make a 2d scatter plot but to use a gradient for the third dimension. Ive seen some gradients used for a proc gmap but I dont know if I can use this for a scatter???

My dataset looks like

a b c
x y N

N is from 0 to 50, so I need 50 colors but I need it displayed as a gradient.

All help appreciated.
Thanks,
Niall
 
If you can set a "color=" option for the point which allows you to set a variable for the colour then all you need to do is calculate the colour for each point in a prior dataset. I've done something similar to this for a 3D scatter-plot turning it into a 4D chart.

creating the colours though is a bit tricky.
Here's a chunk of code I wrote some time back which does exactly that. i haven't looked at this in ages, but I thik this does pretty much what you want.
Code:
data dat1;
  infile cards dlm=',' dsd;

  input rank_frequency
        rank_recency
		rank_value
		count;

		vip = .;

cards;
;

data dat2;
  infile cards dlm=',' dsd;

  input rank_frequency
        rank_recency
		rank_value
		count;

		vip = 1;

cards;
1,0,0,470
1,0,1,66
1,1,1,4616
1,1,2,18
1,2,1,50
1,2,2,5784
2,0,0,1468
2,0,1,274
2,1,1,26773
2,1,2,100
2,2,1,352
2,2,2,88290
;
run;

data alldat;
  set dat1 dat2;
run;

proc summary data=alldat nway;
 class rank_frequency rank_recency rank_value;
 var count;
 output out=allsum(drop=_type_ _freq_) sum=;
run;

proc sql;
  select max(count)  as max
        ,min(count)  as min
  from allsum
  ;
quit;

******
HLS numbers
Hue        = 201       = 0C9 Hex
Light      = variable
Saturation = 86        = 56 HEX

Need to scale the range of Light over the range of our counts
Max count = 110781
Max Light = 256  (actually 255, but it's 0-255)
110781/256 = 432.
****;

data allsum2;
  set allsum;
  
  * value of light variable... *;
  decval = floor(count/433);
  hexval = put(decval,hex2.);

  colour = 'H0CF' !! hexval !! '56';


  *colRGB = "%HLSTORGB(colour)";

run;

proc format;
  value $colfmt
    '' = ''
	;

  value rnkfmt
    0 = 'Low'
	1 = 'Medium'
	2 = 'High'
	;

  value vipfmt
    . = 'Regular'
	1 = 'VIP'
	;
run;

ods html file='C:\coltest.htm';
proc report data=allsum2 nowd;
  columns count colour;

  define count /order;
  define colour /display style=[background=$colfmt.];
run;
ods html close;



goptions reset=all;
proc goptions;
run;


ods html path='c:\'
         file='test.htm';
proc g3d data=allsum2;
  scatter rank_recency*rank_frequency=rank_value /color=colour shape='balloon'
                                                  size=5 noneedle;
run;
quit;
ods html close;

I hope that this helps.
Chris.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top