Rolf Turner
2021-Aug-02 08:34 UTC
[R] Plotting confidence intervals with ggplot, in multiple facets.
I would like to tie off this thread (?!?!) by thanking Jeff Newmiller, Rui Barradas, Avi Gross and Bill Dunlap for their advice and insight. I have attached the code that I finally put together, on the basis of the aforementioned advice, in the file ciPlot.txt. I have also attached the necessary data set in the file egDat.txt. Just in case anyone is interested or in case someone else might benefit from seeing this code. cheers, Rolf Turner -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: ciPlot.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20210802/82eed2b3/attachment.txt> -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: egDat.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20210802/82eed2b3/attachment-0001.txt>
Rui Barradas
2021-Aug-02 16:53 UTC
[R] Plotting confidence intervals with ggplot, in multiple facets.
Hello, I'm glad it helped. Here are a couple of ideas for theme. 1) From ?theme: Theme inheritance Theme elements inherit properties from other theme elements hierarchically. For example, axis.title.x.bottom inherits from axis.title.x which inherits from axis.title, which in turn inherits from text. So there is no need for axis.title.x and axis.title.y (or axis.text) and this theme_bw() + theme(axis.title.x=element_text(size=14), axis.title.y=element_text(size=14)) + theme(axis.text.x=element_text(size=14), axis.text.y=element_text(size=14)) + theme(panel.border=element_rect(linetype="solid",fill=NA), panel.grid.minor=element_blank(), panel.grid.major=element_blank()) can be simplified to this theme_bw() + theme(axis.title=element_text(size=14), axis.text=element_text(size=14)) + theme(panel.border=element_rect(linetype="solid",fill=NA), panel.grid=element_blank()) 2) If you are using the same theme repeatedly, why not define a custom theme? It's as easy as theme_custom <- function(){ theme_bw() %+replace% #replace elements we want to change theme(axis.title=element_text(size=14), axis.text=element_text(size=14), panel.border=element_rect(linetype="solid",fill=NA), panel.grid=element_blank()) } (It's also possible to just copy&paste the two theme instructions in your code, I have rewritten them as one as a matter of habit.) The plots would then become easier to read and if themes' rules change, the theme will be updated in one place only. Part.a <- ggplot(cidf.a, aes(Ndat, estimate)) + geom_errorbar(aes(ymin = lower, ymax = upper), width = 50) + geom_point(size = 1) + geom_hline(yintercept = 0,col="red") + labs(x="",y=Ylab.a) + theme_custom() And the same for Part.b. Hope this helps, Rui Barradas ?s 09:34 de 02/08/21, Rolf Turner escreveu:> > I would like to tie off this thread (?!?!) by thanking Jeff Newmiller, > Rui Barradas, Avi Gross and Bill Dunlap for their advice and insight. > > I have attached the code that I finally put together, on the basis of > the aforementioned advice, in the file ciPlot.txt. I have also > attached the necessary data set in the file egDat.txt. > > Just in case anyone is interested or in case someone else might benefit > from seeing this code. > > cheers, > > Rolf Turner > > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >