# Example 7.5: Replicating a prettier jittered scatterplot

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**SAS and R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The scatterplot in section 7.4 is a plot we could use repeatedly. We demonstrate how to create a macro (SAS, section A.8) and a function (R, section B.5) to do it more easily.

**SAS**

%macro logiplot(x=x, y=y, data=, jitterwidth=.05, smooth=50); data lp1; set &data; if &y eq 0 or &y eq 1; jitter = uniform(0) * &jitterwidth; if &y eq 1 then yplot = &y - jitter; else if &y eq 0 then yplot = &y + jitter; run; axis1 minor=none label = ("&x"); axis2 minor=none label = (angle = 270 rotate = 90 "&y"); symbol1 i=sm&smooth.s v=none c=blue; symbol2 i=none v=dot h=.2 c=blue; proc gplot data=lp1; plot (&y yplot) * &x / overlay haxis=axis1 vaxis=axis2; run; quit;

**R**

logiplot

We’ll load the example data set from the book via the web (section 1.1.6), then make a plot of the real data.

**SAS**

filename myurl url 'http://www.math.smith.edu/sasr/datasets/help.csv' lrecl=704; proc import datafile=myurl out=ds dbms=dlm; delimiter=','; getnames=yes; run; %logiplot(x = mcs, y = homeless, data=ds, smooth=40);

**R**

ds

The resulting plots are quite similar, but still differ with respect to the smoother and the exact jitter applied to each point.

(Click for a bigger picture.)

To

**leave a comment**for the author, please follow the link and comment on their blog:**SAS and R**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.