BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bhr-q
Pyrite | Level 9

Hello all,

I created the plot below using the following code:

bhrq_0-1726666613776.png

proc sgplot data=tmp;
where event in ('b', 'w');
  vbar event / response=score  stat=mean limitstat=CLM  barwidth=0.3;  XAXIS DISPLAY=(nolabel); RUN;

when I try to add the following statement to include individual values:

scatter x=event y=score /jitter markerattrs=(symbol=trianglefilled color=black size=8);

I receive the error:

ERROR: Attempting to overlay incompatible plot or chart types.

 

when I use the other way below it doesn't show me all the 20 obs that I have :

 proc summary data=plot1 nway;
   class event;
   var score;
   output out=work.summary (drop= _: )
      mean= lclm= uclm= / autoname;run;
data work.newplot; set plot1 work.summary ; run;
proc sgplot data=work.newplot; where event in ('b', 'w' ); vbarparm category= event response=score/ barwidth=0.3 limitlower=score_lclm limitupper= score_uclm ; scatter x=event y=score/markerattrs=(color=gray size=6 symbol=trianglefilled) ; run;

it shows: 

bhrq_0-1726671013785.png

there are 11 points in each plot, it should be 20 in each not 11, I meant didn't show me all the obs.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Maybe you have some duplicated value in SCATTERS, add JITTER option in SCATTER statement:
scatter x=event y=score/markerattrs=(color=gray size=6 symbol=trianglefilled) jitter ;

View solution in original post

12 REPLIES 12
PaigeMiller
Diamond | Level 26

Scatter plot and vertical bar chart cannot be on the same plot, they must be on different plots. It's not really clear to me what you mean by "include individual point in bar chart".

--
Paige Miller
bhr-q
Pyrite | Level 9

Thanks, I edited my question, including extra one to show individual point

ballardw
Super User

Data.

What is the question now? We have no data so can't tell what you might mean by "there are around 14 points not 20". Are there supposed to be just 14? If there are more then which 14 are desired.

Since I can count what appears to be 22 markers neither 14 not 20 make sense.

 

bhr-q
Pyrite | Level 9

I meant there should be 20 points for each plot, but here shows 11 points for each plot

yes I  had typo error 11 not 14, sorry.  

ballardw
Super User

Data.

Data

Data

 

How do you expect us to have any idea of what you want or describe what happens without actual data. in the form of a working data set.

 


@bhr-q wrote:

I meant there should be 20 points for each plot, but here shows 11 points for each plot

yes I  had typo error 11 not 14, sorry.  


If you expect XXX number of points and only see YYY and YYY<XXX it almost always means that either 1) you have duplicate values and they are overlaying or 2) you don't actually have XXX points.

If it is one of the above situations it can be answered very quickly by looking at the data.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

bhr-q
Pyrite | Level 9

I didn't expect any one if my question is not clear.

ballardw
Super User

@bhr-q wrote:

I didn't expect any one if my question is not clear.


Your question is extremely "not clear".

You think you should have 20 points and only see 11.

But you won't share the data so we can tell you exactly why you get 11.

 

Show us proc freq output for

Proc freq data=tmp;
   where event in ('b', 'w');
   tables event * score / list missing;
run;
PaigeMiller
Diamond | Level 26

@bhr-q wrote:

Thanks, I edited my question, including extra one to show individual point


I'm lost.

--
Paige Miller
ballardw
Super User

There is a section in the online help for Sgplot/ Sgpanel that has details on "Plot Type Compatibility". Search for it. Memorize it.

The page shows which plots may be used with others.

 

If you every wondered why there are HBAR/VBAR ad HBARPARM/VBARPARM this page might help. If you must overlay a SCATTER plot then you need to overlay with the HBARPARM or VBARPARM.

The Parm bit means you have to pre-summarize the data to set the bar heights.

Ksharp
Super User
Maybe you have some duplicated value in SCATTERS, add JITTER option in SCATTER statement:
scatter x=event y=score/markerattrs=(color=gray size=6 symbol=trianglefilled) jitter ;

bhr-q
Pyrite | Level 9

Thanks so much. I was able to get the answer with your help. Now I have the right plot, 19 points for each plot would be correct. The important thing is that the initial plot showed me a much lower point than I expected; it doesn't matter is it 19 or is it 20, because I have several datasets, and one of them is 19  which shows here.

  my aim was to figure out why show me a much lower point in my second approach

bhrq_0-1726716551333.png

 

I had two approaches in my initial comments:

In my  first way:    I tried using the jitter option with a scatter statement alongside a vertical bar chart. but, I received  an error stating 'overlay incompatible plot,' .

 

In my second approach, I missed to include the jitter option, which resolved the issue, so it would be enough to include “markerattrs=(color=gray size=6 symbol=trianglefilled)jitter” as a last line in my second approach

 

 

bhr-q
Pyrite | Level 9

Thanks again, I also tried to remove the redcap_event_name in the below of my plot, I looked for legend but didn't do.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 1192 views
  • 1 like
  • 4 in conversation