BookmarkSubscribeRSS Feed
mathias
Quartz | Level 8

Hi,

I need to create a barchart for every week since 5 years.

But the xaxis is displaying every label and they are too much.

I have a dataset with weeks in date format (the dates are the sunday of the beginning week)

and a value for each week.

(This dataset was the created with PROC TIMESERIES.)

I have a problem with the display of the XAXIS : every week label is displayed and is not at all readable.

What can I do to avoid this ?

Any help would be very much appreciated.

thank you in advance

Capture.PNG

I'am using GTL

    proc template;

        define statgraph BooleanTimeBarChart;

            begingraph / border=false;

                layout overlay /

                        yaxisopts=(label='Cases / week'

                            griddisplay=on

                            display=(label tickvalues))

                        xaxisopts=(label='week'

                            griddisplay=off

                            display=(tickvalues ticks));

                    barchart x=DateUsedForStatistics y=Cases /

                        group=isAugmenting

                        index=gdataColor

                        barwidth=1

                        name='NameBarchart'

                      

                        outlineattrs=(thickness=0 color=white)

                        datatransparency=.2

                        legendlabel='Color'

                        grouporder=descending;

                    discretelegend 'NameBarchart'/

                        border=false

                        title='isAugmenting';

                    endlayout;

                    endgraph;

                    end;

                    run;

art

I attach the dataset from this chart used in the PROC sgrender

6 REPLIES 6
Jay54
Meteorite | Level 14

What you are seeing is the Discrete axis, where all values are shown.  Bar Chart always creates a discrete axis.  You have two options.    Set the TickValueFitPolicy on the xaxis DiscreteOpts to trim the tick values.  Or, Instead of a bar chart, use a NeedlePlot or HighLowPlot with a real time axis.  This article may be timely for you:   Grouped Timeline - Graphically Speaking

mathias
Quartz | Level 8

Thank you Sanjay

TickValueFitPolicy=thin seems to work but it modifies the chart :

(other TickValueFitPolicy values I picked from examples i found, produce errors)

Capture2.PNG

I'll have a look at the article and try to reproduce that.

mathias
Quartz | Level 8

I don't know what is the cause, but when I ran the program again today with

DiscreteOpts=(TickValueFitPolicy=thin)

, it was correct :

Capture3.PNG

thank you !

Is there a way to force the intervals to be at the beginning of each year ?

mathias
Quartz | Level 8

This the best I can do with the HIGHLOW

Capture4.PNG

+ data ticks are much better

- barwidth=1 does not work, I can play with intervalbarwidth but its an absolute value, thus not dynamic

- group colors are inverted, whatever comes first determines the color

Code

                proc sgplot data=HIGHLOWPLOT  ;

                    *where DateUsedForStatistics>'01jan2013'd;

                    highlow x=DateUsedForStatistics low=low high=high /

                            group=isAugmenting

                            name='a'

                            type=bar

                            barwidth=1

                            discreteoffset=0

                            fill

                            nooutline

                            transparency=.2

                            /*intervalbarwidth=3*/

                            ;

                    *keylegend 'a' / title='Virus' location=inside position=topright across=1;

                    xaxis type=time interval=semiyear offsetmin=0 offsetmax=0;

                    yaxis grid display=(NOTICKS);

                    run;

This is the best I can do with the NEEDLE

Capture5.PNG

same advantages and disadvantages than highlow

- lines are drawn in the legend

Code

                proc sgplot data=HIGHLOWPLOT  ;

                    *where DateUsedForStatistics>'01jan2013'd;

                    needle x=DateUsedForStatistics y=Cases /

                            group=isAugmenting

                            lineattrs=(thickness=2 pattern=solid)

                            transparency=.2

                            ;

                    *keylegend 'a' / title='Virus' location=inside position=topright across=1;

                    xaxis type=time interval=semiyear offsetmin=0 offsetmax=0;

                    yaxis grid display=(NOTICKS);

                    run;

Jay54
Meteorite | Level 14

For HighLow plot, with TYPE=bar the default bar width is 85% of the minimum spacing from data.  There is a bug that is preventing changing bar width as a % when axis is numeric.  But you can provide IntervalBarWidth=value in pixels (or other dimension) to change the default.

Colors are normally assigned in the order the groups are encountered in the data.  You can control this by using a Discrete Attributes Map where you can define the colors (and other attributes) by the group VALUE.  In your case, for values '0' and '1', you can specify that '0' should be blue and '1' should be green.

You can specify the axis start, end and other details.

GraphGuy
Meteorite | Level 14

If you can't get what you want with GTL, you might try this trick I sometimes use in SAS/Graph Gchart. I suppress all the bar text values/labels, and then programmatically annotate the specific ones I want. Here are two examples that show the general technique:

http://robslink.com/SAS/democd71/executions.htm

http://robslink.com/SAS/democd71/executions_info.htm

http://robslink.com/SAS/democd71/fisa_surveillance_orders.htm

http://robslink.com/SAS/democd71/fisa_surveillance_orders_info.htm

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 6 replies
  • 1810 views
  • 3 likes
  • 3 in conversation