BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
marta25
Obsidian | Level 7

Hi,

I am using PROC SGPLOT with HEATMAP and I would like to change the size of the colormap values.

Here is my code and the resulting plot:

PROC SGPLOT data=  MARTA.mydata;
heatmap x=clocktime y=myvariable / colorresponse=aaa  colorstat=mean colormodel=(bigb red) xbinsize=0.25 ;
xaxis label='Clock time' values=(9 to 18 by 1) valueattrs=(size=14pt) labelattrs=(size=14pt);
yaxis label='My variable' valueattrs=(size=14pt) labelattrs=(size=14pt);
gradlegend / title='colormap' titleattrs=(size=14pt)  ;
run;

 

Screenshot 2021-05-26 at 18.42.53.png


My problem seems to be simple but I can not find the solution. The values of the colormap are smaller compared to the other labels and values on the axes.

How to set such values to 14pt?

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

Here's a technique that works in SAS 9.4m7 (and probably earlier versions as well), using a custom ods style to control most of the normal (non-title/non-label) text in the graph. Since I don't have your data, I use some 'random' data from the sashelp sample lib to demonstrate.

 

ods path(prepend) work.templat(update);
proc template;
define style my_style;
parent=styles.htmlblue;
class GraphValueText / font = ("<sans-serif>, <MTsans-serif>",14pt);
end;
run;

 

ods html style=my_style;

 

proc sgplot data=sashelp.class;
heatmap x=height y=weight / colorresponse=weight colorstat=mean colormodel=(bigb red) xbinsize=0.25 ;
xaxis label='Clock time' labelattrs=(size=14pt);
yaxis label='My variable' labelattrs=(size=14pt);
gradlegend / title='colormap' titleattrs=(size=14pt);
run;

 

gradlegend.png

View solution in original post

15 REPLIES 15
Rick_SAS
SAS Super FREQ

The attributes in the interior of the heat map do not know about the attributes for the axis labels or ticks.

 

What do you mean by "the values of the colormap"? Are you talking about the size of the rectangles that show the values of the aaa variable at each cell for (clocktime, myvariable)? If so, use

XBINSIZE=1

on the HEATMAP statement to have the rectangles span one unit in the x direction.  If desired, you can also use the YBINSIZE= option to change the size of the rectangles in the Y direction.

 

ballardw
Super User

If you mean the size of the colored heatmap areas then look at the XBINSIZE or YBINSIZE to specify a specific size. See what happens when you add Xbinsize=1 and Ybinsize=2 to the heatmap statement.

 

or possibly NXBINS and NYBINS (the number of bins). Try NXBINS=10 and NYBINS=10.

There are other binning options as well to examine.

 

Data is important as well. We do not have your data and you don't provide any clues as to "how big" or range of values you want the areas to represent.

GraphGuy
Meteorite | Level 14

To get the size of the text in the legend larger, I believe you can change the size= in the valueattrs= in the gradlegend. Here's the gradlegend valueattrs= example from the doc ...

 

valueattrs=(Color=Green Family=Arial Size=8 
        Style=Italic Weight=Bold) 

 

marta25
Obsidian | Level 7

Hi Robert,

yes that was exactly my question and I had tried valueattrs=(size=...) as you wrote.

 

gradlegend / title='colormap' titleattrs=(size=14pt) valueattrs=(size=14pt);

My problem is that the word "valueattrs" in my code does not turn to blue:

Screenshot 2021-05-26 at 22.00.54.png

 

...resulting in an error:

 

Screenshot 2021-05-26 at 21.56.04.png

 

I don't understand why...

Rick_SAS
SAS Super FREQ

Here is the doc for the GRADLEGEND statement:

https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0pejjes5ug1j2n1roobaiuj9w60.ht...

 

There is no VALUESATTR= option for that statement in PROC SGPLOT. If you really want this, you will have to use the GTL and the CONTINUOUSLEGEND statement: SAS Help Center: CONTINUOUSLEGEND Statement

GraphGuy
Meteorite | Level 14

Oops - sorry about that! I was looking at doc for a variant/version of SAS that you probably don't have. (Hopefully this feature will make its way into the more common versions of of SAS in the near future!)

GraphGuy
Meteorite | Level 14

Here's a technique that works in SAS 9.4m7 (and probably earlier versions as well), using a custom ods style to control most of the normal (non-title/non-label) text in the graph. Since I don't have your data, I use some 'random' data from the sashelp sample lib to demonstrate.

 

ods path(prepend) work.templat(update);
proc template;
define style my_style;
parent=styles.htmlblue;
class GraphValueText / font = ("<sans-serif>, <MTsans-serif>",14pt);
end;
run;

 

ods html style=my_style;

 

proc sgplot data=sashelp.class;
heatmap x=height y=weight / colorresponse=weight colorstat=mean colormodel=(bigb red) xbinsize=0.25 ;
xaxis label='Clock time' labelattrs=(size=14pt);
yaxis label='My variable' labelattrs=(size=14pt);
gradlegend / title='colormap' titleattrs=(size=14pt);
run;

 

gradlegend.png

marta25
Obsidian | Level 7

Thanks for your answer.

It does not really work because now I get an authorization error:

Screenshot 2021-05-27 at 15.37.14.png

GraphGuy
Meteorite | Level 14

Hmm ... are you running SAS through Enterprise Guide, or SAS University Edition, or something like that? 

 

If so, perhaps one of these threads will help:

https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-Get-HTML-output-in-EG-8-2/td-p/623073

https://communities.sas.com/t5/SAS-Analytics-U/Error-Message-in-SAS-University-Edition/td-p/425601

 

 

marta25
Obsidian | Level 7

Thanks, now it kind of works using this code:

ODS HTML path='/folders/myfolders/plots'
         GPATH = '/folders/myfolders/plots/' image_dpi =300;
ods path(prepend) work.templat(update);
proc template;
define style my_style;
parent=styles.htmlblue;
class GraphValueText / font = ("<sans-serif>, <MTsans-serif>",14pt);
end;
run;
ods html path='/folders/myfolders/plots' style=my_style;
proc sgplot data=sashelp.class;
heatmap x=height y=weight / colorresponse=weight colorstat=mean colormodel=(bigb red) xbinsize=0.25 ;
xaxis label='Clock time' labelattrs=(size=14pt);
yaxis label='My variable' labelattrs=(size=14pt);
gradlegend / title='colormap' titleattrs=(size=14pt);
run;

In this way, a .png image is saved together with a .htm file. I don't need this .htm file, is there a way to not generate it (except from deleting it manually)?

Also, can I set the name of the generated file?

 

I used to save plots using:

ods listing gpath='/folders/myfolders/plots';
ods graphics /attrpriority=none imagename="plot_heatmap"  noborder imagefmt=png;

...but I don't know how to set the style here.

Thanks!

GraphGuy
Meteorite | Level 14

Have you tried ods graphics / imagename='plot_heatmap' to control the png name, like you were using before?

 

marta25
Obsidian | Level 7

Yes, this works to set the file name.

ods html path='/folders/myfolders/plots' style=my_style image_dpi=500;
ods listing gpath='/folders/myfolders/plots';
ods graphics /attrpriority=none imagename="heatmap" imagefmt=png;

However I still get a "sashtml.htm" file created every time I create my png plot.

Is there a way to avoid creating this .htm file?

I understand I need to keep "ods html..." to set the style...

 

Many thanks!

GraphGuy
Meteorite | Level 14

I don't know - I've never not wanted the html file 🙂

FreelanceReinh
Jade | Level 19

@marta25 wrote:

Yes, this works to set the file name.

ods html path='/folders/myfolders/plots' style=my_style image_dpi=500;
ods listing gpath='/folders/myfolders/plots';
ods graphics /attrpriority=none imagename="heatmap" imagefmt=png;

However I still get a "sashtml.htm" file created every time I create my png plot.

Is there a way to avoid creating this .htm file?

I understand I need to keep "ods html..." to set the style...

Hello @marta25,

 

You can send the HTML file to "nowhere" (arbitrary fileref, see documentation):

filename nowhere dummy;
ods html file=nowhere gpath='/folders/myfolders/plots' style=my_style image_dpi=500;

 

(I think with your additional ODS LISTING statement you also get a second PNG file, which you could avoid with ods listing close;.)

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 15 replies
  • 1889 views
  • 9 likes
  • 5 in conversation