BookmarkSubscribeRSS Feed
msrenee1984
Obsidian | Level 7

Hello , I wanted to know if there is a way to add column and row totals to my heat map?

 

ods graphics / width=12cm height=50cm;
title "apples eaten Per Facility by Year ";
title2 "apple Counts (N=5952)";
/* basic heat map */
proc sgplot data=freqout; /*temp*/
heatmap x=year y=facility / colorresponse=Count
discretex discretey colormodel=(green redTwoColorRamp)outline ;
yaxis label='Facility Name' valueattrs=(size=4pt) labelattrs=(size=8pt);
xaxis label='Calender Year' valueattrs=(size=5pt) labelattrs=(size=5pt);
text x=year y=facility text=count text=total / textattrs=(size=3pt) ;
run;

1 REPLY 1
MarciaS
SAS Employee

Hi @msrenee1984 

 

You can use the XAXISTABLE and YAXISTABLE statements in PROC SGPLOT to place the row and column totals on the graph.

Below is a sample showing how to do this with your PROC SGPLOT code. 

data freqout; /* Sample data */
  input year facility count;
  datalines;
2021 1 40
2021 2 30
2022 1 10
2022 2 30
2023 1 30
2023 2 40
;
run;
proc sgplot data=freqout noautolegend; /*temp*/
  heatmap x=year y=facility / colorresponse=Count
  discretex discretey colormodel=(green redTwoColorRamp)outline ;
  yaxis label='Facility Name' valueattrs=(size=8pt) labelattrs=(size=8pt);
  xaxis label='Calender Year' valueattrs=(size=8pt) labelattrs=(size=5pt);
  text x=year y=facility text=count / textattrs=(size=8pt) ;
  yaxistable count /position=right valueattrs=(size=8pt) nolabel;
  xaxistable count /position=top valueattrs=(size=8pt) nolabel;
run;

Hope this helps.

 

Regards,

Marcia

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!

How to Concatenate Values

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.

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
  • 1 reply
  • 189 views
  • 0 likes
  • 2 in conversation