.Rmd
file to suppress all code, warnings, and other messages. Use the code chunk header {r set-up, include = FALSE}
to suppress this set up code.::opts_chunk$set(echo = TRUE,
knitrwarning = FALSE,
message = FALSE)
#
and the title, so the header renders correctly. For example, ###Section Title
will not render as header, but ### Section Title
will.{r plot1, fig.height = 3, fig.width = 5}
, replacing plot1
with a meaningful label and the height and width with values appropriate for your write-up.fig_width
and fig_height
options in your YAML header as shown below:---
title: "Your Title"
author: "Team Name + Group Members"
output:
pdf_document:
fig_width: 5
fig_height: 3
---
Replace the height and width values with values appropriate for your write-up.
Arrange plots in a grid, instead of one after the other. This is especially useful when displaying plots for exploratory data analysis and to check assumptions.
If you’re using ggplot2
functions, the patchwork
or ggpubr
packages make it easy to arrange plots in a grid.
If you’re using base R function, i.e. when using the emplogit
functions, put the code par(mfrow = c(rows,columns))
before the code to make the plots. For example, par(mfrow = c(2,3))
will arrange plots in a grid with 2 rows and 3 columns.
Be sure all plot titles and axis labels are visible and easy to read.
coord_flip()
to flip the x- and y-axis on the plot. This is useful if you a bar plot with an x-axis that is difficult to read due to overlapping text.❌ NO! The x-axis is hard to read because the names overlap.
ggplot(data = mpg, aes(x = manufacturer)) +
geom_bar()
✅ YES! Names are readable
ggplot(data = mpg, aes(x = manufacturer)) +
geom_bar() +
coord_flip()
%>%
mpg count(manufacturer) %>%
mutate(manufacturer = str_to_title(manufacturer)) %>%
ggplot(aes(x = fct_reorder(manufacturer,n), y = n)) +
geom_bar(stat = "identity", fill = "steelblue") +
coord_flip() +
labs(x = "Manufacturer",
y = "Count",
title = "The most common manufacturer is Dodge") +
theme_bw()
kable
function from the knitr package to neatly output all tables and model output. This will also ensure all model coefficients are displayed.
digits
argument to display only 3 or 4 significant digits.caption
argument to add captions to your table.<- lm(mpg ~ hp, data = mtcars)
model tidy(model) %>%
kable(digits = 3)
term | estimate | std.error | statistic | p.value |
---|---|---|---|---|
(Intercept) | 30.099 | 1.634 | 18.421 | 0 |
hp | -0.068 | 0.010 | -6.742 | 0 |