BookmarkSubscribeRSS Feed
Joan
Fluorite | Level 6

I was excited to finally get 9.3. I wanted to do some graphs similar to the first graph shown here but with a data table below.

http://blogs.sas.com/content/graphicallyspeaking/2012/03/30/cluster-groups/

In my case, I wanted the y-axis to show the "percent" of the bars, and the data table to show the numerator (row 1) and denominator (row 2) used to calculate the percentage, where the data tables columns are located beneath their respective bar.

I tried to accomplish this task with GTL (using several barchart statements with discreteoffsets, or one barchart statement with the groupdisplay=cluster option) .The chart looks just like I always dreamed it would. However, I have not been able to get the data table I want using blockplot. Blockplot "stacks" the data rather than putting it side-by-side the way the groupdisplay cluster option does. Since I am new to GTL, I wanted to see if this can be done.

I also wondered if using SGPLOT with the groupdisplay=cluster option and the new sganno option might work. But I worried that because of the clustering I might run into related problems aligning the data table with the "x-axis" -- since I don't have a simple x-axis but rather a x*group axis.

Below is some code for one of the approaches I tried, if that's helpful. But I am not wedded to any approach -- I just want to create a data table associated with a "clustered" bar chart like the one above, where each column in the data table aligns (ie.., is directly below) the correct bar in the graph.

Thanks for any suggestions.

layout lattice / rows=4 columndatarange=union rowweights=(0.85 .05 .05 .05);

   layout overlay / cycleattrs=true

   xaxisopts=(display=(tickvalues))

   yaxisopts=(label="Percent" offsetmin=0);

  barchart x=group y=a_pct / name='ac' legendlabel='a' discreteoffset=-0.3 barwidth=0.3 barlabel=true;

  barchart x=group y=b_pct / name='mix' legendlabel='b' discreteoffset=0 barwidth=0.3 barlabel=true;

  barchart x=group y=c_pct / name='wc' legendlabel='c' discreteoffset=+0.3 barwidth=0.3 barlabel=true;

  innermargin;

  blockplot x=groupc block=a_den / display=(values label) valuehalign=right repeatedvalues=true labelattrs=(color=black);

  blockplot x=groupc block=b_den / display=(values label) valuehalign=right repeatedvalues=true labelattrs=(color=black);

  blockplot x=groupc block=c_den / display=(values label) valuehalign=right repeatedvalues=true  labelattrs=(color=black);

  endinnermargin;

  endlayout;

endlayout;

1 REPLY 1
Jay54
Meteorite | Level 14

Please attach the full code with data.

Yes, you can do what you are saying, and line up the data values below each "MIDPOINT" value for the bar chart.  However, you cannot align any values with individual bars.  That depends on the number of groups in each category, etc.

So, you could put the string "m / n" below each midpoint, one for each group value.  Compute this string for each bar and populate it in to a column and then use the BLOCKPLOT to place the string.

If your data is already summarized (by category and group), you can then use SGPLOT VBARPARM to draw the cluster grouped bar chart and use a scatter plot (with markerchar) to place the values below each bar.

With SGPLOT, you can probably use annotate creatively to do what you want, except there is no easy way to know (definitely) the location of each bar in the cluster, as the number of groups present in each category may vary.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1229 views
  • 0 likes
  • 2 in conversation