Hi, I am creating a scatter plot. I am new to the different types of graphs. When I run the code, I am able to generate the graph, however I am not sure how I can achieve that.
1. How I can move the treatments in to middle instead . Presently it printing at the both end of x axis.
2. Please ignore the circle made in green and red. I Just want to show where I want to display the new data points.
3. I need to display the Mean value right to the trt on x axis and median to the left to the trt ( Make sure these are not in the same x axis of data points or too far from the data points.. How I can achieve this because we did not given any values on X axis.
Please give suggestions. Thanks.
Fig 1 How it prints
fig2 How I want
data test;
input Treatment$ trtcode response;
cards;
trt1 1 5
trt1 1 2
trt1 1 3
trt1 1 5
trt1 1 6
trt1 1 1
trt1 1 3
trt1 1 2
trt1 1 0
trt2 2 2
trt2 2 3
trt2 2 4
trt2 2 6
trt2 2 1
trt2 2 9
trt2 2 10
;
run;
ods graphics on/ width= 8in height= 4in ;
options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nofmterr nobyline
noquotelenmax ;
ods results on;
ods listing close;
ods rtf file = "\&location.\dotted-plot.rtf";
proc sgplot data=test;
scatter x=treatment y=response / group=trtcode;
run;
ods _all_ close;
In the future, please do not double-post the same question. It wastes people's time.
Here is my answer from the other thread:
Compute the mean and median, then merge the statistics and the data. As for moving the graphics towards the center of the display, use the OFFSETMIN= and OFFSETMAX= options in the XAXIS statement:
/* compute the means and medians for each treatment group */
proc means data=test;
class Treatment;
var response;
output out=MeansOut mean=Mean median=Median;
run;
/* merge the data and the statistics */
data All;
set test MeansOut(where=(_Type_=1));
run;
proc sgplot data=All;
scatter x=treatment y=response;
scatter x=Treatment y=mean / markerattrs=(symbol=Plus size=16) discreteoffset=-0.1 ;
scatter x=Treatment y=median / markerattrs=(symbol=Star size=16) discreteoffset=0.1;
xaxis type=discrete offsetmin=0.25 offsetmax=0.25;
run;
One way:
proc sgplot data=test; scatter x=treatment y=response / group=trtcode; xaxis offsetmin=.3 offsetmax=.3 ; run;
The offsetmin=.3 says place the smallest value on the xaxis at the 30 percent of the width of the axis, the offsetmax=.3 is 30 percent space above (right) of the largest value. Use values of 0 to 1. The space can be reserved independently, if the max and min total 1 or more the default behavior will return because you attempted to use more than 100 percent of the width of the axis.
Where do you expect to get the mean and medians from? You may find that calculating where to place an x value on a character axis is awkward at best. Often it is better to have a numeric value for the axis with a format to display text like "Trt1" so that you can do things like add other text/markers with small offsets.
If you have more than a small number of points you may want to look at a VBOX instead of Scatter plot as it displays more information about the distribution of values.
@SASuserlot wrote:
Hi, I am creating a scatter plot. I am new to the different types of graphs. When I run the code, I am able to generate the graph, however I am not sure how I can achieve that.
1. How I can move the treatments in to middle instead . Presently it printing at the both end of x axis.
2. Please ignore the circle made in green and red. I Just want to show where I want to display the new data points.
3. I need to display the Mean value right to the trt on x axis and median to the left to the trt ( Make sure these are not in the same x axis of data points or too far from the data points.. How I can achieve this because we did not given any values on X axis.
Please give suggestions. Thanks.
Fig 1 How it prints
fig2 How I want
data test; input Treatment$ trtcode response; cards; trt1 1 5 trt1 1 2 trt1 1 3 trt1 1 5 trt1 1 6 trt1 1 1 trt1 1 3 trt1 1 2 trt1 1 0 trt2 2 2 trt2 2 3 trt2 2 4 trt2 2 6 trt2 2 1 trt2 2 9 trt2 2 10 ; run; ods graphics on/ width= 8in height= 4in ; options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nofmterr nobyline noquotelenmax ; ods results on; ods listing close; ods rtf file = "\&location.\dotted-plot.rtf"; proc sgplot data=test; scatter x=treatment y=response / group=trtcode; run; ods _all_ close;
Hi @ballardw Thanks for the response. Your offset option solved my first query. I do understand your suggestion about the vbox plot. I chose this graph template because of my requirement from statisticians where they want to see drug concentration in plasma and compare with mean/ median (I guess).
I can calculate the mean/ median using Proc Summary
proc summary data= test nway;
var response;
class treatment trtcode;
output out= mean1 (keep=treatment _Mean _median) mean= _mean median=_median;
run;
However, I am not sure do I have to append or merge my mean1 dataset with the test dataset. Because of my requirement in placing the mean/ median data points adjacent to the 'response' data points. unfortunately, they want mean and median data points with different symbols compared to the 'response' data points, Therefore I think we can not append them. Please suggest your thoughts in achieving this. Thank you.
The means/medians could be appended just have the values in different variables. Two different scatter plots would allow you to specify different markers, colors and such as well as adding to the legend. The problem is just what X value you would use. When you have axis values that are text like 'trt1' there is no natural increment to have a value just a bit to the right/left of the other symbols. 'trt.09' for example would be a completely separate text entry and not be "close" to the existing column of 'trt1' values. IF you use a numeric value with a custom format such that 1 displays as 'trt1' and 2 as 'trt2' then you could use X values like 0.8 or 1.2 or similar for the markers of the mean and median. Then on the xaxis statement use values to only display the 1 and 2 and either using the format in a Valuesformat to display 'trt1' or use the ValuesDisplay= option to display text if you don't want to create a format.
Another approach, define the axis as discrete and try the Discreteoffset= option for your mean/median variable scatter plots.
In the future, please do not double-post the same question. It wastes people's time.
Here is my answer from the other thread:
Compute the mean and median, then merge the statistics and the data. As for moving the graphics towards the center of the display, use the OFFSETMIN= and OFFSETMAX= options in the XAXIS statement:
/* compute the means and medians for each treatment group */
proc means data=test;
class Treatment;
var response;
output out=MeansOut mean=Mean median=Median;
run;
/* merge the data and the statistics */
data All;
set test MeansOut(where=(_Type_=1));
run;
proc sgplot data=All;
scatter x=treatment y=response;
scatter x=Treatment y=mean / markerattrs=(symbol=Plus size=16) discreteoffset=-0.1 ;
scatter x=Treatment y=median / markerattrs=(symbol=Star size=16) discreteoffset=0.1;
xaxis type=discrete offsetmin=0.25 offsetmax=0.25;
run;
Sorry @Rick_SAS @ballardw I will keep in mind of it next time ( I thought I can do it in different forum.) I need a suggestion , can you guys please suggest links or documents, to understand the small nuances or things in adjusting the graphs when do ODS RTF outputs, such controlling what access to print, increase or decrease the size of the graph, controlling legends and titles inside the figure or outside etc.. for example, the solution you provided I tried to do RTF output. I don't want the right border ( circled in red).Thanks again.
The documentation is the place to start.
Look at the ODS Graphics statement for things that apply across multiple procedures such as the graphic display area size and such.
The the procedure and statement options.
Many examples with data of different graphing types at Graph Samples Gallery | SAS Support
If you haven't figured it out yet, many specific ODS destinations have there own default ODS style. So you may want to specify the ods style instead of the default as that is the base place for default color schemes and appearance of graph objects like markers and lines plus font type and size.
Thank you. It helped.
Try this one ?
ods rtf file='c:\temp\temp.rtf';
proc sgplot data=All noborder;
scatter x=treatment y=response;
scatter x=Treatment y=mean / markerattrs=(symbol=Plus size=16) discreteoffset=-0.1 ;
scatter x=Treatment y=median / markerattrs=(symbol=Star size=16) discreteoffset=0.1;
xaxis type=discrete offsetmin=0.25 offsetmax=0.25;
run;
ods rtf close;
worked , Thank you.
This Query is Answered Now.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.