Data visualization with SAS programming

Help with clustered barchart and blockplot (GTL)

Occasional Contributor
Posts: 12

Help with clustered barchart and blockplot (GTL)

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.

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


   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;


  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);




Posts: 1,227

Re: Help with clustered barchart and blockplot (GTL)

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.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation