- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have use proc sgplot scatter to create a graph, but I need a line with arrow to point the dots. Here is the example:
I have used function = 'arrow', but I need to make the arrow smaller, which is not possible since I have used the smallest size = 1 and line = 1 to create this arrow. Is there another way to create arrow, since I need it to be smaller?
function='arrow';x1space="datavalue";y1space="datavalue";x2space="datavalue";y2space="datavalue";desc='Arrow';
x1=x_y1;y1=y_y1;
x2=x_y2;y2=y_y2;
line=0.3; size=0.3;
direction='in';linecolor='CXC00000';linepattern='34';linethickness=&t_linethickness.;shape='filled';scale=0.001;
Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You could try VECTOR statement instead.
data x;
input x y x1 y1;
cards;
0 0 1 0
;
proc sgplot data=x;
vector x=x1 y=y1/xorigin=x yorigin=y ARROWHEADSHAPE=filled LINEATTRS=(color=darkred pattern=dash ) ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You could try VECTOR statement instead.
data x;
input x y x1 y1;
cards;
0 0 1 0
;
proc sgplot data=x;
vector x=x1 y=y1/xorigin=x yorigin=y ARROWHEADSHAPE=filled LINEATTRS=(color=darkred pattern=dash ) ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Ksharp! Is there any condition that I can add? because I would like to have a solid line for certain data label, and dash for others. And this can change depending on situation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In the code provided by @Ksharp , add additional VECTOR commands (with different data, different colors and different line patterns).
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
VECTOR plots can be grouped via the GROUP option. Set your data label variable on the GROUP option and you should get the attribute changes on the vectors. If you want only the line pattern to change, I would set ATTRPRIORITY=COLOR on the ODS GRAPHICS statements to ensure that the line pattern changes faster than the color. If you want to control which data label gets a particular line pattern, you can use a discrete attributes map to make that assignment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you @PaigeMiller , @DanH_sas ! I'm pushing the limit here, can I make the size of the arrowhead smaller? It is because I have the graph on a whole page of the powerpoint, and it looks a bit too big. Is this possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You could use SCATTER or TEXT to mock the arrowheader and change its size or color.
data x;
input x y x1 y1 group x2 y2 x3 y3;
cards;
0 0 1 0 1 1 0 . .
0.5 -1 0.5 1 2 . . 0.5 1
;
ods graphics/attrpriority=none;
proc sgplot data=x;
styleattrs datacolors=(red blue) datalinepatterns=(dash solid);
vector x=x1 y=y1/group=group xorigin=x yorigin=y noarrowheads ;
scatter x=x2 y=y2/markerattrs=graphdata1(symbol=trianglerightfilled size=8 );
scatter x=x3 y=y3/markerattrs=graphdata2(symbol=trianglefilled size=20 );
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data x;
input x y x1 y1 group x2 y2 ;
cards;
0 0 1 0 1 1 0 . .
0.5 -1 0.5 1 2 0.5 1 ..
;
ods graphics/attrpriority=none;
proc sgplot data=x;
styleattrs datacolors=(red blue) datalinepatterns=(dash solid) datasymbols=(trianglerightfilled trianglefilled );
vector x=x1 y=y1/group=group xorigin=x yorigin=y noarrowheads ;
scatter x=x2 y=y2/group=group markerattrs=( size=6 );
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks @Ksharp ! Unfortunately, I need the arrow to follow the direction of the lines, so it is not always horizontal or vertical.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just FYI...SERIES plot also supports the arrowhead option. Different data structure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
OK. Try SCATTER statement.
data x;
input x y group m;
cards;
0 0 1 1
1 0 1 1
0.5 -1 2 2
0.5 1 2 2
0.5 0.5 3 .1
1 1 3 .1
;
ods graphics/attrpriority=none;
proc sgplot data=x;
styleattrs datacolors=(red blue) datalinepatterns=(dash solid) ;
series x=x y=y/group=group arrowheadpos=end ARROWHEADSHAPE=filled ARROWHEADSCALE=0.1 thickresp=m;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Oh noo... @Ksharp , series connects all dots together, and I don't want that. This is what I want to have:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use the GROUP option on the SERIES to group your series points based on the label information you showed (Sherly, Robert, etc.). For the SERIES plot, your data will use an X, Y, and GROUP column. There will be 5 observations for the group "Sherly", and two observation for each of the other groups. Do you want each of the line to have the same properties, or do you want them to be different per group?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks @DanH_sas, @Ksharp ! I tried to do that but I don't know why it is big:
Here is my code:
proc sgplot data=prep_graph_&t_i._graph sganno=anno noautolegend noopaque nowall noborder pad=&t_pad.;
styleattrs datacolors=('CXC00000') datalinepatterns=(dot solid);
series x=x_value y=y_value/
datalabel=t_label_f
datalabelattrs=(size=&t_text_size_pt.pt family="&global_font.")
markerattrs=(symbol=squarefilled size=&t_marker_size.px)
group=t_label arrowheadpos=end ARROWHEADSHAPE=filled ARROWHEADSCALE=0.1 thickresp=m;
run;