I am looking to create a scatter plot. when I run my program its giving the default colors and symbols for markers. I would like to know how can I control the colors and symbols of the two different groups in the graph. In the below picture I am getting the red and blue colors by default. I have the following questions.
1. How I can control the color of the each group?
2. In the picture, both have the marker Circle filled, Can I have different symbol for each group?
3. How I can make the dotted line to regular line and regular line into dotted line?
4. In my Template procedure "megedleged" statment staying in red, but no errors in log, do I miss any thing n the code. Please let me know
data ScatCurve; /* example data: scatter plot and curves */
call streaminit(1);
do Group = 1 to 2;
do x = 0 to 5 by 0.2;
Pred = Group + (1/Group)*x - (0.2*x)**2;
y = Pred + rand("Normal",0,0.5);
output;
end;
end;
run;
proc template;
define statgraph ScatCurveLegend;
dynamic _X _Y _Curve _Group _Title; /* dynamic variables */
begingraph;
entrytitle _Title;
layout overlay;
scatterplot x=_X y=_Y / group=_Group name="obs" markerattrs=(symbol=CircleFilled);
seriesplot x=_X y=_Curve / group=_Group name="curves" ;
/* specify exactly two names for the MERGEDLEGEND statement */
mergedlegend "obs" "curves" / border=true title=_Group;
endlayout;
endgraph;
end;
run;
ods rtf file = "C:\Users\xxu\Desktop\New folder\xx_sample.rtf" ;
proc sgrender data=ScatCurve template=ScatCurveLegend;
dynamic _Title="Overlay Curves, Merged Legend"
_X="x" _Y="y" _Curve="Pred" _Group="Group";
run;
ods rtf close;
Thank you for your Reponses.
So, expanding on my suggestion, using STYLEATTRS gets you this code via SGPLOT
proc sgplot data=scatCurve tmplout="/home/fkhurshed/graph_code.sas";
styleattrs datalinepatterns=(dot solid) datasymbols=(trianglefilled circlefilled) ;
scatter x= x y=y / group = group ;
series x= x y = Pred / group = group;
run;
The template then looks like this, with the datasymbols and dataLinePatterns options specified. This is ONE way to do this. Using a data attribute map is another option, and you can replicate this methodolgy to see how to implement it, using this similar question.
proc template; define statgraph sgplot; begingraph / collation=binary subpixel=on dataSymbols=( TRIANGLEFILLED CIRCLEFILLED ) dataLinePatterns=( 34 1 ); layout overlay / yaxisopts=(labelFitPolicy=Split) y2axisopts=(labelFitPolicy=Split); ScatterPlot X='x'n Y='y'n / subpixel=off primary=true Group='Group'n LegendLabel="y" NAME="SCATTER"; SeriesPlot X='x'n Y='Pred'n / Group='Group'n LegendLabel="Pred" NAME="SERIES"; DiscreteLegend "SCATTER"/ title="Group"; endlayout; endgraph; end; run;
You could then modify your template code, the BEGINGRAPH statement to mimic this (and remove the marker option on the SCATTER) and it seems to work.
proc template;
define statgraph ScatCurveLegend;
dynamic _X _Y _Curve _Group _Title; /* dynamic variables */
begingraph / dataSymbols=( TRIANGLEFILLED CIRCLEFILLED ) dataLinePatterns=( 34 1 );
entrytitle _Title;
layout overlay;
scatterplot x=_X y=_Y / group=_Group name="obs" ;
seriesplot x=_X y=_Curve / group=_Group name="curves" ;
/* specify exactly two names for the MERGEDLEGEND statement */
mergedlegend "obs" "curves" / border=true title=_Group;
endlayout;
endgraph;
end;
run;
proc sgrender data=ScatCurve template=ScatCurveLegend;
dynamic _Title="Overlay Curves, Merged Legend"
_X="x" _Y="y" _Curve="Pred" _Group="Group";
run;
Thanks. I am new to graphs. I will play with the code and the references you provided
Have you looked at the DATTRMAP option for Proc Sgrender?
That uses a data set to control attributes of lines and markers based on values you provide.
Thanks for your reply, I am new to graphs, I will search for what you mentioned. Thanks for giving me the direction.
So, expanding on my suggestion, using STYLEATTRS gets you this code via SGPLOT
proc sgplot data=scatCurve tmplout="/home/fkhurshed/graph_code.sas";
styleattrs datalinepatterns=(dot solid) datasymbols=(trianglefilled circlefilled) ;
scatter x= x y=y / group = group ;
series x= x y = Pred / group = group;
run;
The template then looks like this, with the datasymbols and dataLinePatterns options specified. This is ONE way to do this. Using a data attribute map is another option, and you can replicate this methodolgy to see how to implement it, using this similar question.
proc template; define statgraph sgplot; begingraph / collation=binary subpixel=on dataSymbols=( TRIANGLEFILLED CIRCLEFILLED ) dataLinePatterns=( 34 1 ); layout overlay / yaxisopts=(labelFitPolicy=Split) y2axisopts=(labelFitPolicy=Split); ScatterPlot X='x'n Y='y'n / subpixel=off primary=true Group='Group'n LegendLabel="y" NAME="SCATTER"; SeriesPlot X='x'n Y='Pred'n / Group='Group'n LegendLabel="Pred" NAME="SERIES"; DiscreteLegend "SCATTER"/ title="Group"; endlayout; endgraph; end; run;
You could then modify your template code, the BEGINGRAPH statement to mimic this (and remove the marker option on the SCATTER) and it seems to work.
proc template;
define statgraph ScatCurveLegend;
dynamic _X _Y _Curve _Group _Title; /* dynamic variables */
begingraph / dataSymbols=( TRIANGLEFILLED CIRCLEFILLED ) dataLinePatterns=( 34 1 );
entrytitle _Title;
layout overlay;
scatterplot x=_X y=_Y / group=_Group name="obs" ;
seriesplot x=_X y=_Curve / group=_Group name="curves" ;
/* specify exactly two names for the MERGEDLEGEND statement */
mergedlegend "obs" "curves" / border=true title=_Group;
endlayout;
endgraph;
end;
run;
proc sgrender data=ScatCurve template=ScatCurveLegend;
dynamic _Title="Overlay Curves, Merged Legend"
_X="x" _Y="y" _Curve="Pred" _Group="Group";
run;
Thanks for you detailed code, however I have a question extension to previous one, your code give default blue and red colors. Where we can control these?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.