Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
twildone
Pyrite | Level 9

Hi....I am trying to create bar graphs that have both the counts and percentages on the graphs. The problem I am having is the font size on each bar is too small. Is there a way to specifiy the font size or height for the bar labels. Also, I am creating separate bar graphs for each question, is it possible to label the question inside the graph rather than outside the graph and a border. Thanks.

 

 

Axis1 style=1 width=1 minor=none label=(height=9pt font="arial/bold" angle=90  "Percent") value=(height=9pt font="arial" "0%" "10%" "20%" "30%" "40%" "50%" "60%" "70%" "80%" "90%" "100%");
Axis2 style=1 width=2 label=(height=9pt font="arial/bold"   "Response") value=(height=9pt font="arial");
Axis3 label=(height=9pt font="arial/bold"   "Term") value=(height=9pt font="arial");
title;
title1 "PT Survey Data Bar Chart";
footnote;

proc gchart data=Want7;
	vbar Response / discrete group=Term type=percent inside=pct  outside=freq nolegend g100
		coutline=black raxis=axis1 maxis=axis2 gaxis=axis3 woutline=1 patternid=midpoint width=20;
	by Question ;
run; 
quit;

Output:

Question=My experience with course content and the learning environment. - The course content was interesting.




dr.png

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

SGPLOT VBAR can produce a G100 vbar chart.   The proc option PCTLEVEL controls how the VBAR PERCENT is computed.  The SGPLOT vbar category is term instead of  response that is used in GCHART vbar.

 

Example:

I used the variable name answer instead of response.  This was done to help avoid any mindset confusion with the vbar option response=.

The data is pre-counted answers.  Small changes would be needed if the plot data set is one row per respondent (i.e. raw/unsummarized).

option DATALABELATTRS= is used to increase the bar data font size.

 

data have (label="Survey summary count");
question = 'One';
length Term $20 Answer $10;
input term & answer & count;
if term ne lag(term) then answer_seq=1; else answer_seq+1;
datalines;
Fall 2018  Disagree  4
Fall 2018  Neutral   36
Fall 2018  Agree     160
Spring 2019  Disagree  6
Spring 2019  Neutral  24
Spring 2019  Agree  70
;

ods html file='vbar.html';

title "Survey chart";

data need;
  set have;
  count_as_label = count;   * separate var neeed because count is also response=;
run;

proc sgplot data=need pctlevel=group;
  by question;
  vbar term / 
    response=count
    group=answer 
    groupdisplay=cluster
    grouporder=data
    barwidth=0.85
    stat=percent
    datalabel=count_as_label
    datalabel=answer
    datalabelattrs=(size=11pt)

  ;
  xaxis labelpos=right display=(noticks)  ;*tickstyle=inside;
  yaxis display=(nolabel) values=(0 to 1 by .1) offsetmin=0.07;
  keylegend / location=inside position=bottom title="";
run;

ods _all_ close;

sgplot vbar g100.png

View solution in original post

3 REPLIES 3
RichardDeVen
Barite | Level 11

SGPLOT VBAR can produce a G100 vbar chart.   The proc option PCTLEVEL controls how the VBAR PERCENT is computed.  The SGPLOT vbar category is term instead of  response that is used in GCHART vbar.

 

Example:

I used the variable name answer instead of response.  This was done to help avoid any mindset confusion with the vbar option response=.

The data is pre-counted answers.  Small changes would be needed if the plot data set is one row per respondent (i.e. raw/unsummarized).

option DATALABELATTRS= is used to increase the bar data font size.

 

data have (label="Survey summary count");
question = 'One';
length Term $20 Answer $10;
input term & answer & count;
if term ne lag(term) then answer_seq=1; else answer_seq+1;
datalines;
Fall 2018  Disagree  4
Fall 2018  Neutral   36
Fall 2018  Agree     160
Spring 2019  Disagree  6
Spring 2019  Neutral  24
Spring 2019  Agree  70
;

ods html file='vbar.html';

title "Survey chart";

data need;
  set have;
  count_as_label = count;   * separate var neeed because count is also response=;
run;

proc sgplot data=need pctlevel=group;
  by question;
  vbar term / 
    response=count
    group=answer 
    groupdisplay=cluster
    grouporder=data
    barwidth=0.85
    stat=percent
    datalabel=count_as_label
    datalabel=answer
    datalabelattrs=(size=11pt)

  ;
  xaxis labelpos=right display=(noticks)  ;*tickstyle=inside;
  yaxis display=(nolabel) values=(0 to 1 by .1) offsetmin=0.07;
  keylegend / location=inside position=bottom title="";
run;

ods _all_ close;

sgplot vbar g100.png

GraphGuy
Meteorite | Level 14

Is your value=(height=9pt) not affecting the text size? Have you tried a larger value there?

 

twildone
Pyrite | Level 9

Yes...I tried a larger and smaller value and nothing would change.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3212 views
  • 4 likes
  • 3 in conversation