DATA Step, Macro, Functions and more

How to specify plot markers for proc sgplot with attribute map?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to specify plot markers for proc sgplot with attribute map?

I'm trying to implement the solution given in the forum post Proc sgplot: plotting different colors and markers for several groups in a scatter plotbut my plot markers are not changing with group.  Here's my code:

 

* Create attribute map;
data plotattrs;
	retain id "myid";
	length value 3.0 markercolor $ 6 markersymbol $ 6;
	input value markercolor $ markersymbol $;
	datalines;
		1 red plus
		2 green x
	;
run;

* Plot data;
proc sgplot
		data = sashelp.iris
		dattrmap = plotattrs;
	scatter x = petallength y = petalwidth /
		group = species
  		attrid = myid;
run;

 

The plot that is generated represents group by color, but not by marker type:

 

sasPlot.png

 

 

How can I make the plot marker type vary with group like the marker color does?


Accepted Solutions
Solution
‎06-06-2017 07:06 PM
Super User
Posts: 11,343

Re: How to specify plot markers for proc sgplot with attribute map?

The value has to match the value of the group variable.

Try

data plotattrs;
	retain id "myid";
	length value $ 10 markercolor $ 6 markersymbol $ 6;
	input value markercolor $ markersymbol $;
	datalines;
		Setosa red plus
		Versicolor2 green x
      Virginica blue  diamond
	;
run;

* Plot data;
proc sgplot
		data = sashelp.iris
		dattrmap = plotattrs;
	scatter x = petallength y = petalwidth /
		group = species
  		attrid = myid;
run;

View solution in original post


All Replies
Solution
‎06-06-2017 07:06 PM
Super User
Posts: 11,343

Re: How to specify plot markers for proc sgplot with attribute map?

The value has to match the value of the group variable.

Try

data plotattrs;
	retain id "myid";
	length value $ 10 markercolor $ 6 markersymbol $ 6;
	input value markercolor $ markersymbol $;
	datalines;
		Setosa red plus
		Versicolor2 green x
      Virginica blue  diamond
	;
run;

* Plot data;
proc sgplot
		data = sashelp.iris
		dattrmap = plotattrs;
	scatter x = petallength y = petalwidth /
		group = species
  		attrid = myid;
run;
Occasional Contributor
Posts: 5

Re: How to specify plot markers for proc sgplot with attribute map?

Thank you-- I knew I was missing something basic.

Super User
Posts: 11,343

Re: How to specify plot markers for proc sgplot with attribute map?

You may also want to consider using longer text fields by default for you options just so you don't do what I did and tryto stuff "diamond" into a 6 character field.

Occasional Contributor
Posts: 5

Re: How to specify plot markers for proc sgplot with attribute map?

Yeah, I actually caught that one. :-)
Super User
Posts: 10,028

Re: How to specify plot markers for proc sgplot with attribute map?

ods graphics / attrpriority=none;
proc sgplot	data = sashelp.iris;
 styleattrs datacolors=(red yellow blue) ;
	scatter x = petallength y = petalwidth /
	jitter	group = species;
run;
Occasional Contributor
Posts: 5

Re: How to specify plot markers for proc sgplot with attribute map?

[ Edited ]

Thanks for this, Ksharp. I wasn't aware of the "styleattrs" statement in proc sgplot.

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 112 views
  • 1 like
  • 3 in conversation