BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bstarr
Quartz | Level 8

Hello,

 

I have a bar graph developed almost how I need it (using PROC SGPLOT), but the colors are getting reset upon adding a SCATTER statement to my code. I'm trying add some reference points to each series.

 

The data points appear to be getting plotted correctly, which makes me think it's possible to combine the two types, but the colors resetting makes me think it is not possible.

 

I have some code like the following:

data sample;
set sashelp.baseball;
	where team = "Chicago" and Div = "NE";
	ref1 = 15;
	ref2 = 20;
	ref3 = 25;
	ref4 = nHome + 5;
run;

proc sgplot data=sample;
	styleattrs 
		dataColors=(gray darkgray lightgray black)
		dataContrastColors=(gray darkgray lightgray black);

	hbarparm category = Position response=ref3 / barwidth=0.7;
	hbarparm category = Position response=ref2 / barwidth=0.7;
	hbarparm category = Position response=ref1 / barwidth=0.7;
	hbarparm category = Position response=nHome / barwidth=0.4;
	/*scatter y=Position x=ref4;*/
run;

Uncommenting the SCATTER statement plots the data points as intended, but makes all series light blue. Is it possible to control the colors in this scenario? Ideally I'd retain the colors of the bars and make the scatter plot dots orange.

 

I appreciate any help in advance!

 

Thank you,

Brian

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Add the CYCLEATTRS option to the PROC SGPLOT statement. What is happening is that CYCLEATTRS is automatically enabled when all of your plot statements are the same type. When you added the SCATTER statement, we could not automatically determine if CYCLEATTRS is what you wanted. You can always force it using the option.

 

Hope this helps!
Dan

View solution in original post

3 REPLIES 3
Reeza
Super User

Have you tried data attribute maps?

https://documentation.sas.com/?docsetId=grstatgraph&docsetTarget=n1oq0axfb1tc1yn10kgw6dyuitk2.htm&do...

 

I tried specifying the colours using fillattrs option on each HBARPARM and that didn't seem to work unfortunately. 

 

 

DanH_sas
SAS Super FREQ

Add the CYCLEATTRS option to the PROC SGPLOT statement. What is happening is that CYCLEATTRS is automatically enabled when all of your plot statements are the same type. When you added the SCATTER statement, we could not automatically determine if CYCLEATTRS is what you wanted. You can always force it using the option.

 

Hope this helps!
Dan

bstarr
Quartz | Level 8
Yes that worked perfect, thank you!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 562 views
  • 2 likes
  • 3 in conversation