[R] Plotting confidence intervals with ggplot, in multiple facets.

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Tue Jul 20 01:24:05 CEST 2021



Thanks to Jeff Newmiller, Rui Barradas and Avi Gross for their
extremely helpful replies.  I have got both Jeff's and Rui's code to
run.  I am currently experimenting with Avi's suggestion of producing
multiple plots and then putting them together using plotgrid() or
grid.arrange().  This idea seems to me to be most promising in terms of
a desideratum that the y-axis scales/limits should be different on the
two facets.  Also the y-axis labels.

And speaking of y-axis labels:  is it possible in ggplot() to get
mathematical notation in axis labels, titles and possibly other
annotation?  (In the manner of plotmath() in base R graphics.)
Specifically I'd like to get the Greek letters alpha and beta in the
y-axis labels.  In base R graphics I'd do something like
ylab=expression(paste("bias in ",beta)) .  Is there an appropriate
analogue in ggplot()?  (I think that I may have asked this question
before, some time back, but have forgotten the answer.)

cheers,

Rolf

P.S.  The following is kind of apropos of nothing, but it might serve as
a useful warning to others of a Trap for Young Players.  I nearly went
mad (madder?) for a very long time when trying to get Rui's code to run.
I kept getting errors of the form:

> Error in source("scr.Rui") : scr.Rui:6:2: unexpected input
> 5: ggplot(eg, aes(Ndat, estimate)) +
> 6:   
>     ^

Took me an unconscionably long while to figure out what was going on.
I could not see why Jeff's code ran without problem, while Rui's (which
was very similar) fell over.  Turns out the second character in the
offending line is a non-printing character, the 160th member of the
ASCII character set. (It can be produced using "\u00A0".)  Apparently
this is a "non-breaking space". Whatever that means.  It does NOT get
treated as white space in the usual way, and triggers the foregoing
error.

Presumably this invisible character got introduced, into the code that
Rui emailed, by one of the (many!) infuriating idiosyncrasies of
Windoze.  Yet another reason, among the many millions of such, not to
use Windoze.

R.

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-help mailing list