For SAS, we have to make two separate variables-- one with the CESD for the females, and another for the males. For the other gender, these gender-specific variables will have missing values. We'll do this using conditioning (section 1.11.2).
libname k "c:\book";
if female eq 1 then femalecesd = cesd;
else malecesd = cesd;
Now we can use the bubble2 statement (close kin of the plot2 statement, section 5.1.2) to add both gender-specific variables to the plot. While we're at it, we relabel the x-axis to no longer be gender specific and specify that the right y-axis is not to be labeled.
proc gplot data = twocolors;
bubble malecesd*age=i1 / bscale = radius bsize=200
bcolor = blue bfill = solid;
bubble2 femalecesd*age=i1 / bscale = radius bsize = 200
bcolor = pink bfill = solid noaxis;
As in the previous bubble plot example, the scale is manipulated arbitrarily so that the SAS and R figures are similar.
We're somewhat fortunate here that the range of the two gendered CESD scores are similar
In the comments for Example 7.28, we suggested the following simple R code.
femalealc = subset(ds, female==1 & substance=="alcohol")
malealc = subset(ds, female==0 & substance=="alcohol")
with(malealc, symbols(age, cesd, circles=i1,
with(femalealc, symbols(age, cesd, circles=i1,
inches=1/5, bg="pink", add=TRUE))
While this does generate a plot, it could be misleading, in that the scale of the circle sizes is relative to the largest value within each symbols() call. While this could be desirable, it's more likely that we'd like a single scale for the circles. R code for this can be made in a single statement:
symbols(age, cesd, circles=i1,inches=1/5,
Here the ifelse() function (section 1.11.2) generates a different circle fill color depending on the value of female.
The resulting plots are shown below.