BookmarkSubscribeRSS Feed
bsriv
Calcite | Level 5

Hi,

 

I'm trying to get a scatter plot to overlay my box plot with proc sgplot vbox.  The box plot looks great but it's not showing the individual data points.  I've exhaustively searched the forum, and this is what I could come up with:

 

title "Individual Resting State Network Connectivities";
proc sgplot data=new_t 
vbox col1 / group=_name_ ;
scatter x=_name_ y=col1 / jitter transparency=1.0
markerattrs=(color=black symbol=CircleFilled);
run;

 

What am I missing???

 

Thanks!

 

12 REPLIES 12
Reeza
Super User

Depends on your version of SAS, not all versions support this type of overlays. 

 

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=p0yud64khw8fuin1xgr85dgxbb7t.htm&docs...

 

However, there are workarounds and this has been asked and answered before. 

 

https://blogs.sas.com/content/graphicallyspeaking/2015/12/23/box-plot-with-stat-table-and-markers/

 

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/overlay-jitter-scatter-plot-on-boxplot-in-...

https://blogs.sas.com/content/graphicallyspeaking/2012/10/30/violin-plots/

 

Another possible cause is TRANSPARENCY = 1 ->

 

TRANSPARENCY=value

specifies the degree of transparency for the plot. The transparency that you specify applies to all aspects of the plot statement.

Default 0.0
Range 0 (completely opaque) to 1 (completely transparent)

 

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=p1lcbd3lhs3t3bn1jk6d8sjt2yqx.htm&docs...

 


@bsriv wrote:

Hi,

 

I'm trying to get a scatter plot to overlay my box plot with proc sgplot vbox.  The box plot looks great but it's not showing the individual data points.  I've exhaustively searched the forum, and this is what I could come up with:

 

title "Individual Resting State Network Connectivities";
proc sgplot data=new_t 
vbox col1 / group=_name_ ;
scatter x=_name_ y=col1 / jitter transparency=1.0
markerattrs=(color=black symbol=CircleFilled);
run;

 

What am I missing???

 

Thanks!

 


 

bsriv
Calcite | Level 5

Thanks- I'm using SAS university but I tried a computer with SAS 9.4 and was having the same problems.   Either way, none of the links posted provide "workarounds" or am I missing something?   Thanks!

Reeza
Super User

It works fine for me out of the box, SAS University Edition, so you have some other issue, either the transparency or something else in your data. 

 

Run the solution from here, which you should be able to do on any SAS installation out of the box:

 

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/overlay-jitter-scatter-plot-on-boxplot-in-...

 


@bsriv wrote:

Thanks- I'm using SAS university but I tried a computer with SAS 9.4 and was having the same problems.   Either way, none of the links posted provide "workarounds" or am I missing something?   Thanks!


 

bsriv
Calcite | Level 5

If I change group to category it works but then the order is messed up, and the colors are gone.  Is there a way to do in group or have the categories colored?

Reeza
Super User

There probably is. 

This would be much much easier if you used the SASHELP.CARS data set and showed the code you currently have, the graph getting produced and what changes you want made. I'm guessing at this point.

 


@bsriv wrote:

If I change group to category it works but then the order is messed up, and the colors are gone.  Is there a way to do in group or have the categories colored?


 

bsriv
Calcite | Level 5

First with "category"

 

proc transpose data=sashelp.cars out=new_t;
by Make;
run;

 

title "Cars";
proc sgplot data=new_t;
vbox Col1 / category=_name_ ;
scatter x=_name_ y=col1 / jitter transparency=0.0
markerattrs=(color=black symbol=CircleFilled);
run;

 

Screen Shot 2018-02-14 at 11.13.17 AM.png

 

Then with group 

proc transpose data=sashelp.cars out=new_t;
by Make;
run;

 

title "Cars";
proc sgplot data=new_t;
vbox Col1 / group=_name_ ;
scatter x=_name_ y=col1 / jitter transparency=0.0
markerattrs=(color=black symbol=CircleFilled);
run;

 

Screen Shot 2018-02-14 at 11.15.56 AM.png

Then group and group order descend

proc transpose data=sashelp.cars out=new_t;
by Make;
run;

 

title "Cars";
proc sgplot data=new_t;
vbox Col1 / group=_name_ grouporder=descending;
scatter x=_name_ y=col1 / jitter transparency=0.0
markerattrs=(color=black symbol=CircleFilled);
run;
 

Screen Shot 2018-02-14 at 11.17.48 AM.png

 

Reeza
Super User

Isn't the first one correct? Though the scale is not the same so I'm not sure of the value of trying to show these variables in the same plot when they have varying widely scales? Perhaps looking at them one a time may work better?

 

Looking at only MPG which is on the same scale:

 

title "Cars";
proc sgplot data=new_t;
where _name_ =: 'MPG';
vbox Col1 / category=_name_ ;
scatter x=_name_ y=col1 / jitter transparency=0.0
markerattrs=(color=black symbol=CircleFilled);
run;
bsriv
Calcite | Level 5

It is correct in the sense it shows the scatter plot superimposed on the boxplot.

 

BUT- how do I get the boxes to be different colors AND how do I get this to display in descending order?

 

 

Reeza
Super User

@bsriv wrote:

It is correct in the sense it shows the scatter plot superimposed on the boxplot.

  


So your original question is answered.

 


 

BUT- how do I get the boxes to be different colors AND how do I get this to display in descending order?

 


And you have a new DIFFERENT question. GROUPORDER=DESCENDING works for me to change the order, but this depends on how you define DESCENDING. If you define it differently you can force it with a format instead.

 

And try a discrete attribute table to set the colours. 

bsriv
Calcite | Level 5

The issue is that group order descending  works, I can't see the scatterplot with "group" only with "category", for which I can't use grouporder...

Reeza
Super User

Presort your data in desired order?

Reeza
Super User

And one other option,  take the SGPLOT code, get the GTL code using TMPLOUT and modify that instead.

 

title "Cars";
proc sgplot data=new_t tmplout='C:\_localdata\temp\myfile.sas';
where _name_ =: 'MPG';
vbox Col1 / category=_name_ ;
scatter x=_name_ y=col1 / jitter transparency=0.0 
markerattrs=(color=black symbol=CircleFilled);
run;

Generates:

 

proc template;
define statgraph sgplot;
dynamic _ticklist_;
begingraph / collation=binary;
EntryTitle "Cars" /;
layout overlay / xaxisopts=(labelFitPolicy=Split) x2axisopts=(labelFitPolicy=Split) xaxisopts=(discreteOpts=(sortOrder=ascendingFormatted)) xaxisopts=(type=Discrete discreteOpts=(tickValueList=_ticklist_ tickvaluefitpolicy=SplitRotate tickValueListPolicy=Union)) x2axisopts=(discreteOpts=(sortOrder=ascendingFormatted)) x2axisopts=(type=Discrete discreteOpts=(tickValueList=_ticklist_ tickvaluefitpolicy=SplitRotate tickValueListPolicy=Union));
   BoxPlot X=_NAME_ Y=COL1 / primary=true LegendLabel="COL1" NAME="VBOX";
   ScatterPlot X=_NAME_ Y=COL1 / subpixel=off jitter=auto Markerattrs=( Color=CX000000 Symbol=CIRCLEFILLED) DataTransparency=0 LegendLabel="COL1" NAME="SCATTER";
   DiscreteLegend "VBOX" "SCATTER";
endlayout;
endgraph;
end;
run;

GTL gives you more control over the graphics but it's definitely harder to learn and work with compared to SGPLOT.

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
  • 12 replies
  • 3734 views
  • 0 likes
  • 2 in conversation