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

Hello,

I try to do an histogram with this code (I find it on a sas blog). I want to overlay 4 histograms.

I do not find how to diminish the size of the bar and the color.

Thanks for your help.

Nathalie

 

proc sgplot data=myo.fc2;
	where total = 4;
  histogram edgemyosifc / binwidth=1 transparency=0.5 
               name="edge" legendlabel="edgefc" scale = count;
  histogram deseqmyosifc / binwidth=1 transparency=0.5 
               name="deseq" legendlabel="deseqfc" scale = count;
histogram voommyosifc / binwidth=1 transparency=0.5 
               name="voom" legendlabel="voomfc" scale = count;
histogram trendmyosifc / binwidth=1 transparency=0.5 
               name="trend" legendlabel="trendfc" scale = count;

  xaxis label="Fold change " min=-7 max =5 values=(-7 to 5 by 0.5) ;
  keylegend "edge" "deseq" "voom" "trend" / across=1 position=TopRight location=Inside;
run;

Nathalie1_0-1671532769040.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You need to describe what you mean by "diminish size". Do you want to change height or width of bars? The size of the whole graph display area? All bars? For only one or two variables?

 

You can specify a color for each plot using the FILLATTRS option.

For example if you wanted to make the Edgemyosifc red you would use:

  histogram edgemyosifc / binwidth=1 fillattrs=(color=red transparency=0.5) 
               name="edge" legendlabel="edgefc" scale = count;

Add a Fillattrs for each histogram that you want to change from the default color that is set by your current ODS style.

You could also change ODS style and all colors may change depending on choice.

View solution in original post

4 REPLIES 4
ballardw
Super User

You need to describe what you mean by "diminish size". Do you want to change height or width of bars? The size of the whole graph display area? All bars? For only one or two variables?

 

You can specify a color for each plot using the FILLATTRS option.

For example if you wanted to make the Edgemyosifc red you would use:

  histogram edgemyosifc / binwidth=1 fillattrs=(color=red transparency=0.5) 
               name="edge" legendlabel="edgefc" scale = count;

Add a Fillattrs for each histogram that you want to change from the default color that is set by your current ODS style.

You could also change ODS style and all colors may change depending on choice.

Nathalie1
Obsidian | Level 7

Thank you for your response.

I want diminish the width of each bar of the 4 histograms. And I want others colors for each histogram.

I find an other solution, but I don't know if it is possible with my data. I have 4 quantitative variables and one categorical variable.

Here, is the example, I found on blog sas. But, It was only for one quantitative variable.

Nathalie1_0-1671537822944.png

 

ballardw
Super User

@Nathalie1 wrote:

Thank you for your response.

I want diminish the width of each bar of the 4 histograms. And I want others colors for each histogram.

I find an other solution, but I don't know if it is possible with my data. I have 4 quantitative variables and one categorical variable.

Here, is the example, I found on blog sas. But, It was only for one quantitative variable.


I've shown how to set colors for each: provide Fillattrs with a different color for each histogram statement.

 

What "width" do you want for your bars? The nature of a histogram is such that you may not be able to make them narrower. We would have to see example data for the variables to tell if that is possible. Also different bars have different widths in your original graph. Which specific bars need to be narrow? To what width?

You have now added a categorical variable but have not mentioned at all how you want to use it. If you want to overlay the four variables similar to what you have in your original graph for each level of your categorical variable then perhaps you would would want SGPanel with your category variable as the Panelby variable. That creates one graph for each level of the categorical using similar histogram statements.

 

Best is to provide an example of your data as data step code.

 

Proc univariate is more intended for exploration of data and doesn't overlay multiple variables.

Nathalie1
Obsidian | Level 7

I obtained with your help this histogram with width bar diminished.

 

But I think it is perhaps the other solution that is best  (in my previous post, example found in blog sas).

Here, is my data,  I have a qualitative variable = total (1 to 4), I must do a graph with each value of total. And the graph must have 4 graphs with each method (edge, deseq, voom, trend).

But I realize, the other qualitative is missing to my data : the method!!!

Thank you for your help.

Sincerely yours,

Nathalie

 

Nathalie1_1-1671561006653.png

 

Nathalie1_0-1671560669125.png

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1132 views
  • 2 likes
  • 2 in conversation