5.6 Saving your plot

In Chapters 12 and 13 we’ll show you how to export descriptive text, figures, and tables directly from R to Word/PDF/HTML using the power of R Markdown. The ggsave() function, however, can be used to save a single plot into a variety of formats, namely "pdf" or "png":

If you omit the first argument - the plot object - and call, e.g., ggsave(file = "plot.png) it will just save the last plot that got printed.

Text size tip: playing around with the width and height options (they’re in inches) can be a convienient way to increase or decrease the relative size of the text size on the plot. Look at the relative font sizes of the two versions of the ggsave() call, one 5x4, the other one 10x8 (Figure 5.12):

Experimenting with the width and height options within `ggsave()` can be used to quickly change how big or small some of the text on your plot looks like.

FIGURE 5.12: Experimenting with the width and height options within ggsave() can be used to quickly change how big or small some of the text on your plot looks like.

That is, formulating clear questions and seeking to answer them using available datasets.

Again, we emphasise the importance of understanding the underlying data through visualisation, rather than relying on statistical tests or, heaven forbid, the p-value alone.

There are five chapters. Testing for continuous outcome variables (6) leads naturally into Linear regression (7). We would expect the majority of actual analysis done by readers to be using the methods in Chapter 7 rather than 6. Similarly, Testing for categorical outcome variables (8) leads naturally to Logistic regression (9), where we would expect the majority of work to focus. Chapters 6 and 8 however do provide helpful reminders of how to prepare data for these analyses and shouldn’t be skipped. Time-to-event data introduces survival analysis and includes sections on the manipulation of dates.