Hi, there:
I want to change "Squarefilled" marker to "Square with horizontal bar" in the code & the picture below.
data test;
input x y lower upper @@;
datalines;
1 10 8 11 2 11 10 14 3 13 10 14
4 13 11 15 5 14 12 16
;
run;
proc sgplot data=test;
scatter x=x y=y / yerrorlower=lower yerrorupper=upper
markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
keylegend / noborder;
run;
I want to change this like the following picture.
To use LEGENDITEM Statement in SGPLOT seems to be an answer for my question, but this statement applies to SAS9.4M5 and to later releases. And my SAS is 9.4M3.
Please help me. Thank you in advance.
This version uses annotation.
data test;
input x y lower upper @@;
datalines;
1 10 8 11 2 11 10 14 3 13 10 14
4 13 11 15 5 14 12 16
;
run;
%sganno;
data anno;
%sgline(x1=2.8,
y1=6.43,
x2=3.05,
y2=6.43,
drawspace='datavalue',
linethickness=1);
run;
proc sgplot data=test sganno=anno;
series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled
color=blue) lineattrs=(color=blue pattern=solid thickness=0);
scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper
markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
keylegend "series" / noborder;
run;
Square filled marker with a line makes sense if you have a series plot with markers. if you use SERIES plot with MARKERS, you should get a merged legend showing the marker with a line automatically. I don't think you can get that if you only use the SCATTER statement.
Hi, Mr. Sanjay:
Thank you for your response.
Like you said, I used SERIES statement with MARKERS option, and I got the result below.
data test;
input x y lower upper @@;
datalines;
1 10 8 11 2 11 10 14 3 13 10 14
4 13 11 15 5 14 12 16
;
run;
proc sgplot data=test;
series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled color=blue) lineattrs=(color=blue pattern=solid);
scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper
markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
keylegend "series" / noborder;
run;
I don't need lines that connect plots, but I can't find options to extinguish them.
Are there any option, etc. to delete them?
Thank you for your kind cooperation.
@KentaMURANAKA wrote:
Hi, Mr. Sanjay:
Thank you for your response.
Like you said, I used SERIES statement with MARKERS option, and I got the result below.
data test; input x y lower upper @@; datalines; 1 10 8 11 2 11 10 14 3 13 10 14 4 13 11 15 5 14 12 16 ; run; proc sgplot data=test; series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled color=blue) lineattrs=(color=blue pattern=solid); scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid); keylegend "series" / noborder; run;
I don't need lines that connect plots, but I can't find options to extinguish them.
Are there any option, etc. to delete them?
Thank you for your kind cooperation.
You requested a legend with a bar through the symbol. If there is no line through the symbol then having the legend appear that way implies something not displayed, i.e. the line through the symbol, is missing in the actual plot. I think that you need to decide which is more important, the legend appearance or the legend actually matching the graph.
Hi, ballarbw:
Thank you for your response.
Of course, I understand what you said, and I think whichever is good, "marker with bar" or "only marker".
But now I'm trying to re-analyze specific data, and previous result is expressed in the way I questioned.
Are there no options? I'm sorry, but please help me.
The annotate facility will let you create a lot of stuff but that would be automatic. You have to provide location coordinates, for line segments start and end, color, line type, symbol and color as well as you having to provide coordinates that do not overlap other graph elements.
So create the legend for the SCATTER plot ant then create an annotate data set to add the line. There are a number of macros to help. Look at %SGLINE documentation to build a short line segment.
Hi, ballardw:
Thank you for response.
Annotate Function......It feels like difficult for me now.
Mmm
You can get a combined marker and line in the legend if you use SERIES with the MARKER option. You can set the line thickness=0.
Hi, Mr. Sanjay:
Thank you for your response.
Like you said, I used THICKNESS=0 and got the following result.
But also in Legend, I want marker&line. Are there any options, which delete line only in graph, not legend?
I can't find, sorry.
Let me add more information.
I'm trying to re-analyze data (Who conducted the first analysis, I don't know).
They probably analyze using SAS, so I believe we can accomplish one I questioned.
data test;
input x y lower upper @@;
datalines;
1 10 8 11 2 11 10 14 3 13 10 14
4 13 11 15 5 14 12 16
;
run;
proc sgplot data=test;
series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled color=blue)
lineattrs=(color=blue pattern=solid thickness=0);
scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper
markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
keylegend "series" / noborder;
run;
Add a legenditem statement, and then update the keylegend statement to only show the legenditem.
data test;
input x y lower upper @@;
datalines;
1 10 8 11 2 11 10 14 3 13 10 14
4 13 11 15 5 14 12 16
;
run;
proc sgplot data=test;
series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled
color=blue) lineattrs=(color=blue pattern=solid thickness=0);
scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper
markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
legenditem type=markerline name="seriestype" /
markerattrs=(symbol=squarefilled color=blue)
lineattrs=(color=blue pattern=solid thickness=1)
label='y';
keylegend "seriestype" / noborder;
run;
EDITED TO ADD: Legenditem statement is new in SAS 9.4M5, so won't work if you are using SAS 9.4M3. Sorry!
This version uses annotation.
data test;
input x y lower upper @@;
datalines;
1 10 8 11 2 11 10 14 3 13 10 14
4 13 11 15 5 14 12 16
;
run;
%sganno;
data anno;
%sgline(x1=2.8,
y1=6.43,
x2=3.05,
y2=6.43,
drawspace='datavalue',
linethickness=1);
run;
proc sgplot data=test sganno=anno;
series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled
color=blue) lineattrs=(color=blue pattern=solid thickness=0);
scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper
markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
keylegend "series" / noborder;
run;
Hi, Ms. Suzanne, All:
Thank you for your response.
Thanks to your code, I accomplished my objective.
Thanks a lot, All.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.