BookmarkSubscribeRSS Feed
SAS Employee

Want to make your charts more playful? Well, why not replace the bars with images!


Let's start with a normal, and perhaps not so exciting bar chart.


data Xmas;
  input Year Gifts;	
2017 11
2018 8
2019 12
2020 19
2021 5
/* Bar Chart */ ods graphics / reset width=600px height=400px imagename='Xmas gifts Bar Chart'; title;footnote; proc sgplot data=Xmas noborder noautolegend; vbar year / response=Gifts datalabel datalabelattrs=(size=12 weight=bold); xaxis display=(noticks noline nolabel) integer; yaxis display=(nolabel noticks noline) min=0 integer grid; run;


And here is the resulting image. Perfectly fine.


Barchart med ram.png


Now let's do a scatter plot using the SYMBOLIMAGE statement, plotting out a suitable Santa instead of the bars.

The image file santa.png is not included in this article, so google and get yourself a nice image or just take whatever you've got to test this out.

/* Add variable for position of the value (text statement) a bit above the image */
data Xmas_Image;
  set Xmas;
  Gifts_Text_location = Gifts+5;

%let IMGPATH=%str(C:\temp);
ods graphics / reset width=600px height=400px imagename='Xmas gifts with image';
proc sgplot data=Xmas_Image noborder noautolegend;
  symbolimage name=Santa image="&IMGPATH.\santa.png";
  scatter x=Year y=Gifts / markerattrs=(symbol=Santa size=110);
  text x=Year y=Gifts_Text_location text=Gifts / textattrs=(size=20 weight=bold color=white) strip position=left backlight=0.75;
  xaxis display=(noticks noline nolabel) integer offsetmin=0.15 offsetmax=0.15;
  yaxis display=none offsetmin=0.2 offsetmax=0.2;


And here we are!

Santa chart med ram.png





Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Discussion stats
  • 0 replies
  • 1 in conversation