BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sskt
Obsidian | Level 7

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
FreelanceReinh
Jade | Level 19

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;

View solution in original post

11 REPLIES 11
Reeza
Super User

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?

 


 

sskt
Obsidian | Level 7

Thank you for your response.
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.

ballardw
Super User

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?

 


 

sskt
Obsidian | Level 7

Thank you for your response.
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.

ballardw
Super User

@sskt wrote:

Thank you for your response.
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.

sskt
Obsidian | Level 7

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;
FreelanceReinh
Jade | Level 19

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;
sskt
Obsidian | Level 7

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?

FreelanceReinh
Jade | Level 19

@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. 

sskt
Obsidian | Level 7

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.

image.png

FreelanceReinh
Jade | Level 19

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 11 replies
  • 1918 views
  • 7 likes
  • 4 in conversation