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

I am trying to make a plot in PROC SGPANEL with an axis break. Using

 

data new;
   input Type $1 Value;
   datalines;
A 10
B 15
C 12
D 17
E 205
F 225
;
run;

proc sgplot data=new;
   vbar type / response=value;
   yaxis ranges=(0-20 200-230);
run;

(this is from https://support.sas.com/kb/55/683.html) works well in SGPLOT, but I seem to be unable to do something similar in SGPANEL. Any ideas ?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

To emulate the behavior of PROC SGPANEL, you can use the 

ODS LAYOUT GRIDDED

statement to arrange a set of plots that are produced by using PROC SGPLOT.  You can use the 
BY statement in PROC SGPLOT to produce a set of plots, each of which will have a broken axis.

For example:

data new;
   input Group Type $ Value;
   datalines;
1 A 10
1 B 15
1 C 12
1 D 17
1 E 205
1 F 225
2 A 12
2 B 18
2 C 19
2 D 10
2 E 215
2 F 212
;

/* use PROC SORT, if necessary, to sort the data by the BY group */

ods graphics / width=300px height=250px;
ods layout gridded columns=2 advance=BYGroup column_gutter=5px;

proc sgplot data=new;
   by Group;
   vbar type / response=value;
   yaxis ranges=(0-20 200-230);
run;

ods layout end;

View solution in original post

13 REPLIES 13
Ksharp
Super User
You could try LOG type axis:

rowaxis type=log;
karlbang
Fluorite | Level 6

Thank you for the suggestion. 

Rick_SAS
SAS Super FREQ

To emulate the behavior of PROC SGPANEL, you can use the 

ODS LAYOUT GRIDDED

statement to arrange a set of plots that are produced by using PROC SGPLOT.  You can use the 
BY statement in PROC SGPLOT to produce a set of plots, each of which will have a broken axis.

For example:

data new;
   input Group Type $ Value;
   datalines;
1 A 10
1 B 15
1 C 12
1 D 17
1 E 205
1 F 225
2 A 12
2 B 18
2 C 19
2 D 10
2 E 215
2 F 212
;

/* use PROC SORT, if necessary, to sort the data by the BY group */

ods graphics / width=300px height=250px;
ods layout gridded columns=2 advance=BYGroup column_gutter=5px;

proc sgplot data=new;
   by Group;
   vbar type / response=value;
   yaxis ranges=(0-20 200-230);
run;

ods layout end;

karlbang
Fluorite | Level 6

Thank you. I can see how this would work (even if I was hoping for an easier solution)

SimonYT
Calcite | Level 5
Hi Dr Wicklin,

I need to create a panel plot with 4 subsidiary scatter plots, with a broken Y axis, and I also need to insert a different Pearson correlation coefficient for each scatter plot. SGPANEL allow me to use the INSET statement with variables, but the INSET statement in SGPLOT only allows me to use text strings. Is there any solution please?
Rick_SAS
SAS Super FREQ

use PROC SGPLOT to create whatever graphs you want. Use ODS LAYOUT gridded to arrange them into a panel.

SimonYT
Calcite | Level 5
Thanks! Then I have to use several proc sgplot steps to make it happen. It seems there is one step no solution.
ballardw
Super User

If the hold up is the placement of text then you might want to look at the TEXT plot.

Add a variable to hold the Text you want to display with the X, Y coordinates in the same variables as the Scatter plot.

 

data addedtext;
   infile datalines dlm=',';
   length textval $ 50;
   input textval height weight ;
datalines;
Short side of graph,50,60
Tall side of graph,70,120
;


data toplot;
   set sashelp.class
       addedtext
   ;
run;

proc sgplot data=toplot;
   scatter x=height y=weight/group=sex nomissinggroup;
   text x=height y=weight text=textval/ 
           ;
run;
SimonYT
Calcite | Level 5
Thanks! The inset statement can do something similar. I have 4 different scatter plots with broken Y axis to be placed into one panel. Neither the inset nor the text statement allows for a 'group' option, which means we may have to use four different sgplot steps under one 'ods layout' statement to realize a panel plot.
ballardw
Super User

@SimonYT wrote:
Thanks! The inset statement can do something similar. I have 4 different scatter plots with broken Y axis to be placed into one panel. Neither the inset nor the text statement allows for a 'group' option, which means we may have to use four different sgplot steps under one 'ods layout' statement to realize a panel plot.

You need to describe exactly what you mean by "group" option. Because the TEXT statement does use a group option though maybe not in the way that you want.

 

Really, you should start you own thread, provide example data and the sgplot you have tried so far.

 

For one thing since this thread was marked "solved" many people won't bother looking. Another thing is that the original poster of a question you can mark a solution as accepted.

SimonYT
Calcite | Level 5
Thanks for taking time, appreciated. This is a follow-up question, no need to start a new thread, as people searching online will find related messages grouped together by the same thread. I don't quite understand your personal 'should' and 'should not'. I posted my though and contributed to the same thread. If it bothers you, you may step aside please.
For your question, yes, I can make it clear. By 'group' I mean variable, for example, the inset statement within sgpanel can accept variable values, not just texts or strings. Does this answer your question?
ballardw
Super User

@SimonYT wrote:
Thanks for taking time, appreciated. This is a follow-up question, no need to start a new thread, as people searching online will find related messages grouped together by the same thread. I don't quite understand your personal 'should' and 'should not'. I posted my though and contributed to the same thread. If it bothers you, you may step aside please.
For your question, yes, I can make it clear. By 'group' I mean variable, for example, the inset statement within sgpanel can accept variable values, not just texts or strings. Does this answer your question?

But it isn't.

You want Scatter, OP is VBAR. They are different plots and react differently when combined, or attempted, with other plots.

OP was ONLY concerned with the AXIS, you want INSET text or similar.

 

And you haven't actually clarified the group issue because TEXT statement Group= option does take a variable, in fact pretty much requires one when used.

 

Not to mention the OP provides some data and attempted plot code...

SimonYT
Calcite | Level 5
I want to stop this discussion, as it’s non-sense to the broader scope of readers.

For your question, I suggest you to read SAS Manual’s Inset statement under ‘sgpanel’, which is different from that of sgplot in that it takes on variable values. Hope you understand my point.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 13 replies
  • 2486 views
  • 6 likes
  • 5 in conversation