Data visualization with SAS programming

How to make the sgplot code workable?

Accepted Solution Solved
Reply
Contributor
Posts: 74
Accepted Solution

How to make the sgplot code workable?

Hello,

 

Based on the code below,  I  have a couple of questions unsolved. Would you please help me? Thank you so much!

1. How can I put the vertical axis the percentage data ranging from 0% to 100% instead of '0% to 80%'?

2. I added reftick option as the code below, but why there is no '0% ,20%, 40%, 60%, 80%', just a naked parallel vertical axis.

3.  I also added a label beside it as ' Second rate', as the axis on the left side shows , but why  the ' Second rate' does not show off ?

4.  I remove the noautolegend option, but why I can only have two small blocks showing 2 colors, for which I am supposed to have four blocks showing 4 colors instead,

5. Apart from color reminder, can I add a piece of block and a piece of line also, to remind readers that what color and what shape represents what color?

6. How can I move the legend showing 4 colors and 4 shapes down and put it ahead of 'd_2015','d_2015','d_2015_2', 'd_2016_2' respectively so that the readers can figure out what color adn what shape represents what data at first sight.

 

 

data ds1;
input year $ mid $ resp1 resp2;
mid2=cat(strip(mid), "_2");
datalines;
null d_2016 0.45 0.64
null d_2015 0.35 0.783
s_300 d_2016 0.65 0.67
s_300 d_2015 0.55 0.75
s_640 d_2016 0.42 0.89
s_640 d_2015 0.65 0.87
s_670 d_2016 0.35 0.12
s_670 d_2015 0.75 0.09
s_700 d_2016 0.83 0.06
s_700 d_2015 0.47 0.07
s_730 d_2016 0.48 0.18
s_730 d_2015 0.58 0.21
s_760 d_2016 0.67 0.05
s_760 d_2015 0.69 0.045
; run;

data attrmap;
length value FillColor LineColor TextColor $12;
Id='X'; Value="d_2015"; FillStyleElement='graphdata1'; LineStyleElement='graphdata1'; TextStyleElement='graphdata1';output;
Id='X'; Value="d_2016"; FillStyleElement='graphdata2'; LineStyleElement='graphdata2'; TextStyleElement='graphdata2';output;
Id='X'; Value="d_2015_2"; FillStyleElement='graphdata3'; LineStyleElement='graphdata3'; TextStyleElement='graphdata3';output;
Id='X'; Value="d_2016_2"; FillStyleElement='graphdata4'; LineStyleElement='graphdata4'; TextStyleElement='graphdata4';output;
run;

ods listing gpath='.' image_dpi=200;
ods graphics / reset attrpriority=color width=5in height=3in imagename='Goodgraph';
title 'Score Distribution';
proc sgplot data=ds1 noborder cycleattrs dattrmap=attrmap;
vbarparm category=year response=resp1 / group=mid groupdisplay=cluster
outlineattrs=(color=black) barwidth=0.8 attrid=X;
series x=year y=resp2 / group=mid2 smoothconnect attrid=X
lineattrs=(thickness=3);
xaxistable resp1 / class=mid colorgroup=mid attrid=X;
xaxistable resp2 / class=mid2 colorgroup=mid2 attrid=X;
xaxis display=(nolabel) label="Year";
yaxis offsetmin=0 label="Rate" tickvalueformat= percent7.0
REFTICKS label="Second Rate" tickvalueformat= percent7.0;
run;


Accepted Solutions
Solution
‎12-12-2016 10:49 AM
SAS Super FREQ
Posts: 1,080

Re: How to make the sgplot code workable?

See answer to previous similar post.  Use option REFTICKS=(Label values).

In this case, the right axis is a copy of left axis.  Use VALUES option to set the axis range.

View solution in original post


All Replies
Solution
‎12-12-2016 10:49 AM
SAS Super FREQ
Posts: 1,080

Re: How to make the sgplot code workable?

See answer to previous similar post.  Use option REFTICKS=(Label values).

In this case, the right axis is a copy of left axis.  Use VALUES option to set the axis range.

Contributor
Posts: 74

Re: How to make the sgplot code workable?

Hi Sanjay,

 

Thank you so much for your help! Do you know how to add the title' Score distribution' into the head of the image, instead of separating from the image? because I will generate three graphs in sas ods and put them into one PPT slide automatically and each graph needs to have a title at the top, respectively ' Score distribution1' , ' Score distribution2', ' Score distribution3', would you please give me suggestions? Thanks a lot!

SAS Super FREQ
Posts: 889

Re: How to make the sgplot code workable?

The TITLE statement should do that for you automatically, unless you are using the NOGTITLE option on the ODS destination.

Contributor
Posts: 74

Re: How to make the sgplot code workable?

Hi Dan,

 

Unfortunately it wont work. Another question, based on the code above, do you know how to make the graph generated by sgplot smaller? Thanks!

Grand Advisor
Posts: 10,210

Re: How to make the sgplot code workable?

SG graphics size is controlled by the ODS Graphics options height and width:

ODS Graphics /height = 3in width=7in;

Before the graphics procedure would have a size of 3 inches high by 7 inches wide. Look for other measurement options in the documentation.

Contributor
Posts: 74

Re: How to make the sgplot code workable?

Hi Ballard,

 

Thank you so much for your help! It works! also, based on the code above, can you please help me figure out how to change the fontweight and fontsize of  the label value, such as label="Rate" label="Second Rate" (please see the code above), I want to change the fontsize of  "Rate"  and "Second Rate'? Thanks!

SAS Super FREQ
Posts: 1,080

Re: How to make the sgplot code workable?

[ Edited ]

May I suggest that, often, a simple search on Google like "sas sgplot axis label font size" will provide you many answers very quickly. 

Same applies for other things like graph size, etc.  You can also find many examples on Graphically Speaking Blog.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 310 views
  • 2 likes
  • 4 in conversation