Obsidian | Level 7

## How can I make a skipping x-axis in sgplot with non-uniform spacing?

I would like to create a graph similar to the one on the following page.

https://communities.sas.com/t5/Graphics-Programming/sgplot-vline-jitter-standard-error-bars/td-p/457...

In gplot, I can specify a skipping value with values in axis2 of goptions, but
value = ('1' '4' '12' '14' '32' '34')
In sgplot, specifying by xaxis does not work.
Specifically, I have values in the x-axis that are not regular, like 1,4,12,14,32,34.
I do not want to display any other labels.
(With sgplot, if I only display certain labels, they will be equally spaced, but I want to avoid this. I would like them to be displayed on the same scale as the number line.)

How should we handle this in sgplot?

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

Hello @sskt,

I think the default is a discrete x-axis for VLINE plots (as these are often used with a category variable), hence the equal spacing. But you can override this default by adding the TYPE=LINEAR option to the XAXIS statement. You may also want to add the VALUESHINT option to make the existing MIN= and MAX= options effective.

`xaxis type=linear min=0 max=15 values=(1, 4, 12, 14) valueshint;`
11 REPLIES 11
Super User

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

A combination of Min/Max/Values option on the XAXIS statement.

``````proc sgplot data=sashelp.class;
scatter x=age y=weight;
xaxis min=0 max=20 values=(1, 4, 12, 14);
run;``````

@sskt wrote:

I would like to create a graph similar to the one on the following page.

https://communities.sas.com/t5/Graphics-Programming/sgplot-vline-jitter-standard-error-bars/td-p/457...

In gplot, I can specify a skipping value with values in axis2 of goptions, but
value = ('1' '4' '12' '14' '32' '34')
In sgplot, specifying by xaxis does not work.
Specifically, I have values in the x-axis that are not regular, like 1,4,12,14,32,34.
I do not want to display any other labels.
(With sgplot, if I only display certain labels, they will be equally spaced, but I want to avoid this. I would like them to be displayed on the same scale as the number line.)

How should we handle this in sgplot?

Obsidian | Level 7

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

I have tried your plan, but it is still equally spaced, and I would like the graph to be spaced a few lines apart on the x-axis.

Super User

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

If your variable that the " value = ('1' '4' '12' '14' '32' '34') " represents is actually a character valued variable you have to go to significant work to get values to sort properly as "4" is greater than "12" in character values.

And since Character values are treated as categories there is no proportional space that appears between them. Your values would be treated like they were 'A' 'B' 'C' as "distance" between values is not a concept for character in Sgplot.

You likely need to reconsider your data to make a numeric variabl before plotting.

@sskt wrote:

I would like to create a graph similar to the one on the following page.

https://communities.sas.com/t5/Graphics-Programming/sgplot-vline-jitter-standard-error-bars/td-p/457...

In gplot, I can specify a skipping value with values in axis2 of goptions, but
value = ('1' '4' '12' '14' '32' '34')
In sgplot, specifying by xaxis does not work.
Specifically, I have values in the x-axis that are not regular, like 1,4,12,14,32,34.
I do not want to display any other labels.
(With sgplot, if I only display certain labels, they will be equally spaced, but I want to avoid this. I would like them to be displayed on the same scale as the number line.)

How should we handle this in sgplot?

Obsidian | Level 7

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

The quotation marks are the way to write the goption in gplot.
For sgplot, writing it as a number without quotation marks does not work.

Super User

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

@sskt wrote:

The quotation marks are the way to write the goption in gplot.
For sgplot, writing it as a number without quotation marks does not work.

A counter example where values as numbers without quotes work quite well:

```proc sgplot data=sashelp.class;
scatter x=height y=weight;
xaxis values=(50, 53, 60, 68);
run;```

So, when you claim that something "does not work" you need to prove by providing actual data and complete code.

I used numbers without quotes on Axis statements all the time. So without complete Axis definition and Gplot code plus data I have to question your statement on that basis as well.

Obsidian | Level 7

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

My code is as follows.

``````proc sgplot data=data;
vline visit /
response=bp
group=group
stat=mean
markers
limitstat=stddev;
format group groupf.;
xaxis min=0 max=15 values=(1, 4, 12, 14);
run;``````

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

Hello @sskt,

I think the default is a discrete x-axis for VLINE plots (as these are often used with a category variable), hence the equal spacing. But you can override this default by adding the TYPE=LINEAR option to the XAXIS statement. You may also want to add the VALUESHINT option to make the existing MIN= and MAX= options effective.

`xaxis type=linear min=0 max=15 values=(1, 4, 12, 14) valueshint;`
Obsidian | Level 7

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

The issue about spacing has been resolved. Thank you.
I was not aware of these options and could not find out about them, so I am glad I asked here.

However, the labels for the values specified in value are now only partially displayed.
Is there any way to solve this?

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

@sskt wrote:

However, the labels for the values specified in value are now only partially displayed.
Is there any way to solve this?

Can you show an example (code and screenshot or description) where this happens? It didn't occur with the sample data I used to test my modification of your code.

Obsidian | Level 7

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

Regarding the labels being only partially displayed, I am thinking that since they are so long horizontally, if I make them vertical, they will all be displayed. (I am getting a Note like "Some of the scale values have been thinned out").
My version of SAS is M6 and the labels are still horizontal even with valuesrotate=vertical. How can I make them vertical?

The images are confidential and cannot be displayed, but I will post some of them.

## Re: How can I make a skipping x-axis in sgplot with non-uniform spacing?

Thanks for the screenshot and the description. Same here with SAS 9.4M5 if I label the tick marks "Value 1", "Value 2", ... instead of 1, 2, ... (using a format).

You need to add the FITPOLICY= option, e.g.,

`fitpolicy=rotate`

to the XAXIS statement in order to make the VALUESROTATE= option effective or to save space horizontally in other ways. See the various possible values of the FITPOLICY= option in the documentation.

Discussion stats
• 11 replies
• 1723 views
• 7 likes
• 4 in conversation