Data visualization with SAS programming

How to create a "dumbbell" graph?

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How to create a "dumbbell" graph?

I'm trying to create a "dumbbell" graph in which lines for different y-values run horizontal and begin/end in large circles with numerical x-values. 

 

I'm using SAS 9.4 and have tried 2 different types of graphical overlays - both have the issue that I can't figure out how to center the text in the "dumbbells" (circles) at the beginning and end of the lines. I'm including a pdf of the graphs I created (I'm not worried about colors, etc. at this point). Here is my code (slightly simplified):

 

title1 'Attempt #1';

data sx;

input sx value lohi $;

datalines;

1 50 lo

1 75 hi

2 10 lo

2 60 hi

3 2  lo

3 30 hi

;

run;

 

proc sgplot data=sx;

series x=value y=sx / group=sx;

scatter x=value y=sx / group=lohi markerattrs=(size=30) datalabelattrs=(color=black) datalabelpos=center;

run;

 

title1 'Attempt #2';

data sxlohi;

input sx lo hi;

datalines;

1 50 75

2 10 60

3 2  30

;

run;

 

proc sgplot data=sxlohi;

scatter  x=lo y=sx / markerattrs=(size=30);

scatter  x=hi y=sx / markerattrs=(size=30);

highlow y=sx low=lo high=hi / lowlabel=lo highlabel=hi;

run;

 

Is there a simpler way to make "dumbbell" graphs? Or a way to tweak this code?

 

Any thoughts would be appreciated! Thanks!

 

 


Accepted Solutions
Solution
‎06-22-2017 01:07 PM
SAS Super FREQ
Posts: 3,630

Re: How to create a "dumbbell" graph?

See the example about halfway down the article "Compute a weighted mean",

The example uses the BUBBLE statement for the circles (but scatter should work, too)

and uses the TEXT statement with the STRIP option.

 

 

View solution in original post


All Replies
Solution
‎06-22-2017 01:07 PM
SAS Super FREQ
Posts: 3,630

Re: How to create a "dumbbell" graph?

See the example about halfway down the article "Compute a weighted mean",

The example uses the BUBBLE statement for the circles (but scatter should work, too)

and uses the TEXT statement with the STRIP option.

 

 

New Contributor
Posts: 2

Re: How to create a "dumbbell" graph?

That worked - thank you!
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 168 views
  • 0 likes
  • 2 in conversation