BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chris2377
Quartz | Level 8

Dear all,

How can I combine dot plot and bar chart? I've tried the following code:

data have;

     input id $1. bar dot1 dot2;

     datalines;

          a 10 8 7

          b 15 18 3

          c 5 20 1

          d -5 8 2

     ;

run;

proc sgplot data=have;

  vbar id/response=bar;

  dot id/response=dot1;

  dot id/response=dot2 ;

run;

but got an:

ERROR: All overlays must have the same orientation.

I would like to obtain something similar to the attached graph.

Thanks for help


bar_dot_excel.png
1 ACCEPTED SOLUTION

Accepted Solutions
djrisks
Barite | Level 11

Hello,

In SGPLOT, you can only use dotplot with horizontal categorization plot statements. In your code you are trying to overlay a vertical plot with a horizontal plot and that is why you get that error.

You can use GTL to achieve what you want. Please try this code below:

proc template;
  define statgraph barwithdot;
    begingraph;
   layout overlay;
     barchart x=id y=bar / orient = vertical;
  scatterplot x=id y=dot1 / markerattrs=(color=red symbol=squarefilled);
  scatterplot x=id y=dot2 / markerattrs=(color=green symbol=trianglefilled);
   endlayout;
endgraph;
  end;
run;

proc sgrender data = have template = barwithdot;
run;

Thank you.

View solution in original post

4 REPLIES 4
djrisks
Barite | Level 11

Hello,

In SGPLOT, you can only use dotplot with horizontal categorization plot statements. In your code you are trying to overlay a vertical plot with a horizontal plot and that is why you get that error.

You can use GTL to achieve what you want. Please try this code below:

proc template;
  define statgraph barwithdot;
    begingraph;
   layout overlay;
     barchart x=id y=bar / orient = vertical;
  scatterplot x=id y=dot1 / markerattrs=(color=red symbol=squarefilled);
  scatterplot x=id y=dot2 / markerattrs=(color=green symbol=trianglefilled);
   endlayout;
endgraph;
  end;
run;

proc sgrender data = have template = barwithdot;
run;

Thank you.

chris2377
Quartz | Level 8

Thanks a lot djrisks. It works fine.

Best

djrisks
Barite | Level 11

You're welcome 🙂

Jay54
Meteorite | Level 14

The SGPLOT DOT plot is horizontally oriented.  So, you could use an HBAR statement instead.

proc sgplot data=have;

  hbar id/response=bar nostatlabel;

  dot id/response=dot1 nostatlabel markerattrs=graphdata1(symbol=circlefilled size=10);

  dot id/response=dot2 nostatlabel markerattrs=graphdata2(symbol=trianglefilled size=10);

run;

Dot.png

sas-innovate-2024.png

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.

 

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
  • 4 replies
  • 6831 views
  • 4 likes
  • 3 in conversation