Click here to see the SAS code.
Click here to see the example.
---------------------------------------------------------------
This is a sas/graph imitation of the chart found on p. 2 of
the following worldpublicopinion.org doc.
It looks like a somewhat simple chart, but I had to use several 'tricks'
to get it to look just like the original...
Left & right-justified bars:
The right bar isn't really right-justified - it is actually
the 3rd segment of a stacked bar chart, with the middle segment
being white ('invisible'). And since the 3 segments add up to
100, the right edges look nice & straight.
Legend:
Legends are usually in alphabetical (or numeric) order.
There are several tricks to ordering the legend, but the one
I chose to use was assigning numeric values which were in
the order I wanted, and then creating a user-defined format
(legend_fmt.) that would make those numeric values print as
the desired text (1='Mainly positive', 2='', 3='Mainly negative').
Bar segment order:
Each bar is made of 3 segments (or subgroups) - blue, white, orange.
It is important that they're in that order, left-to-right.
The same numeric value as controlled the order of the legend
also controls the ordering of the bar segments.
Bar order:
By default the bars would be ordered alphabetically by the
text/midpoint value associated with the bars. The alternative
to this is to use the ascending/descending options, so the bars
are ordered by the sum value (height) of the bars. But in this
case, all the (3-segment) bars have a height of 100 - so even
though at first glance you might think the descending option
would work, that's not really the case. To overcome this problem,
I used 'proc sort' to order the bars in the desired order (sorting
them by a variable that I'm not even plotting, actually), and
then assigned a new variable (barorder) as the numeric order
of the bars. Then, on-the-fly I create a user-defined-format
(based on the data values) using the 'cntlin' trick, so that
these barorder numbers will print as the name of the country.
Labels:
I used 'annotate' to put the value of the bars on them.
Back to Samples Index