BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Esterina
Obsidian | Level 7

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:

Esterina_0-1707887487667.png

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

Ksharp_0-1707894035259.png

 

View solution in original post

22 REPLIES 22
Ksharp
Super User

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;

Ksharp_0-1707894035259.png

 

Esterina
Obsidian | Level 7

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.

PaigeMiller
Diamond | Level 26

In the code provided by @Ksharp , add additional VECTOR commands (with different data, different colors and different line patterns).

--
Paige Miller
DanH_sas
SAS Super FREQ

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. 

Esterina
Obsidian | Level 7

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?

Ksharp
Super User

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;

Ksharp_0-1707966815290.png

 

Ksharp
Super User
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;

Ksharp_0-1707967105987.png

 

Esterina
Obsidian | Level 7

Thanks @Ksharp ! Unfortunately, I need the arrow to follow the direction of the lines, so it is not always horizontal or vertical.

Esterina_0-1707968265556.png

 

Jay54
Meteorite | Level 14

Just FYI...SERIES plot also supports the arrowhead option.  Different data structure.

Ksharp
Super User

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;

Ksharp_0-1707969458601.png

 

Esterina
Obsidian | Level 7

Thanks @Jay54 , @Ksharp ! Oh..   what is m? I never use series before, I'll take a look how to change my data structure for this. Currently because i have x1, y1, x2, y2, etc.

Esterina
Obsidian | Level 7

Oh noo... @Ksharp , series connects all dots together, and I don't want that. This is what I want to have:

Esterina_0-1707971082268.png

 

DanH_sas
SAS Super FREQ

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?

Esterina
Obsidian | Level 7

Thanks @DanH_sas@Ksharp  ! I tried to do that but I don't know why it is big:

Esterina_0-1708012530349.png

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 22 replies
  • 1410 views
  • 10 likes
  • 5 in conversation