BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Stalk
Pyrite | Level 9
 
proc sgplot data=main_subset PCTLEVEL=GRAPH;
styleattrs datacolors=(Red Blue) datacontrastcolors=(Red Blue);
vbar Sample_name  / response =  Read_Mean  group=Replicate  groupdisplay = cluster nooutline Clusterwidth=0.8 datalabel
    stat=mean dataskin=pressed;
 
  xaxis display=(nolabel noticks) discreteorder=data FITPOLICY=ROTATE;
  yaxis label="% Total  " ;
 keylegend /title='' noborder autooutline;
run;
 
I want to have over lay graph with my standard deviation column name Read_std. Do I need to have low and high columns?
Stalk_0-1701467716571.png

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
infile cards expandtabs truncover;
input Sample_name :$20.	Replicate $ Read_Mean	Read_std;
YERRORUPPER=Read_Mean+1.96*Read_std;
YERRORLOWER=Read_Mean-1.96*Read_std;
cards;
Ad-Ct25	En	99.9981137	0.004001
Ad-Ct25	Mg	99.8808502	0.077763
Ad-Ct28	En	99.8575861	0.241182
Ad-Ct28	Mg	92.0169639	1.59308
Ad-Ct31	En	93.3995416	3.462698
Ad-Ct31	Mg	55.0308563	7.835461
Ad-Ct34	En	42.7004962	8.213055
Ad-Ct34	Mg	16.445265	3.89857
;

proc sgplot data=have;
vbarparm category=Sample_name response=Read_Mean/group=Replicate nooutline groupdisplay=cluster displaybaseline=off;
scatter x=Sample_name y=Read_Mean/YERRORUPPER=YERRORUPPER YERRORLOWER=YERRORLOWER 
group=Replicate groupdisplay=cluster markerattrs=(size=0)  ERRORBARATTRS=(thickness=2) ;
run;

Ksharp_0-1701761336666.png

 

View solution in original post

6 REPLIES 6
ballardw
Super User

Use VBARBASIC instead of VBAR to allow use of series or scatter and bar graph in the same graph.

 

I am not sure what you  mean by "Do I need to have low and high columns?". If you are looking at setting the upper/lower value of an error bar then that might be the YERRORUPPER and YERRORLOWER options in the SCATTER plot.

DanH_sas
SAS Super FREQ

As @ballardw was saying, you can use vbarbasic to render the mean-calculated bar chart and allow a scatter overlay. The VBARPARM statement also has more flexible overlay support, but you would have to do the calculation outside of the procedure. You will need high and low columns to hold the limit values for your scatter plot. The code will looks something like the following:

 

proc sgplot data=main_subset PCTLEVEL=GRAPH;
styleattrs datacolors=(Red Blue) datacontrastcolors=(Red Blue);
vbarbasic Sample_name  / response =  Read_Mean  group=Replicate  groupdisplay = cluster nooutline Clusterwidth=0.8 datalabel
    stat=mean dataskin=pressed;
scatter x=Sample_name y=StdDev / noerrorcaps yerrorupper=UpperVar yerrorlower=LowerVar datalabel;
  xaxis display=(nolabel noticks) discreteorder=data FITPOLICY=ROTATE;
  yaxis label="% Total  " ;
 keylegend /title='' noborder autooutline;
run;
Stalk
Pyrite | Level 9

Here is my data and below is my graph.  Not sure how to calculate high, low values for StDev from Read_std. I want to show my Read_std range on the top of vbar to show the range like in blue ?

Sample_name Replicate Read_Mean Read_std
Ad-Ct25 En 99.9981137 0.004001
Ad-Ct25 Mg 99.8808502 0.077763
Ad-Ct28 En 99.8575861 0.241182
Ad-Ct28 Mg 92.0169639 1.59308
Ad-Ct31 En 93.3995416 3.462698
Ad-Ct31 Mg 55.0308563 7.835461
Ad-Ct34 En 42.7004962 8.213055
Ad-Ct34 Mg 16.445265 3.89857

Stalk_1-1701702211002.png

 

DanH_sas
SAS Super FREQ

I would create a little data step to calculate the high and lows relative to the mean. Something like this:

 

data main_subset2;

set main_subset;

high = read_mean + read_std;

low = read_mean - read_std;

run;

 

Then, use main_subset2 in your SGPLOT call. Use the HIGH and LOW variables in the YERRORUPPER and YERRORLOWER options, respectively.

Ksharp
Super User
data have;
infile cards expandtabs truncover;
input Sample_name :$20.	Replicate $ Read_Mean	Read_std;
YERRORUPPER=Read_Mean+1.96*Read_std;
YERRORLOWER=Read_Mean-1.96*Read_std;
cards;
Ad-Ct25	En	99.9981137	0.004001
Ad-Ct25	Mg	99.8808502	0.077763
Ad-Ct28	En	99.8575861	0.241182
Ad-Ct28	Mg	92.0169639	1.59308
Ad-Ct31	En	93.3995416	3.462698
Ad-Ct31	Mg	55.0308563	7.835461
Ad-Ct34	En	42.7004962	8.213055
Ad-Ct34	Mg	16.445265	3.89857
;

proc sgplot data=have;
vbarparm category=Sample_name response=Read_Mean/group=Replicate nooutline groupdisplay=cluster displaybaseline=off;
scatter x=Sample_name y=Read_Mean/YERRORUPPER=YERRORUPPER YERRORLOWER=YERRORLOWER 
group=Replicate groupdisplay=cluster markerattrs=(size=0)  ERRORBARATTRS=(thickness=2) ;
run;

Ksharp_0-1701761336666.png

 

Stalk
Pyrite | Level 9

Perfect. Thank you so much ballardw, Dan and Ksharp. This is exactly what I need.
@Dan, Sorry for my delayed reposnse, I was trying on my real data where the response values are very low (0.002) for one replicate and 99.9 for another replicate. Having hard time to show on the same scale. All is well now. Thank you

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
  • 6 replies
  • 944 views
  • 0 likes
  • 4 in conversation