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





Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.


Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 


Register now!

Discussion stats
  • 0 replies
  • 1 in conversation