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.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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
  • 3 replies
  • 653 views
  • 2 likes
  • 3 in conversation