Occassionally you want to do all your exploratory data analysis (EDA) and results in one RMarkdown file but you want to hide certain results and plots that you used during your EDA, and expose specific ones. E.g. This happens for business communications where information is exposed as needed for the audience youโre communicating to.
If you want to do all your work in the RMarkdown document, have your code be evaluated but suppress the output of models, plots etc. you can use:
results = "hide"
: suppress printing results to document.fig.keep = "none"
: suppress printing of plots to document.```{r lin-reg, echo = FALSE, eval = TRUE, results="hide", fig.keep = "none"}
ggplot(mtcars, aes(x = disp, y = mpg)) +
geom_point() +
geom_smooth()
model_lin <- lm(mpg ~ disp + wt, data = mtcars)
summary(model_lin)
```
Note that the results="hide"
and fig.keep = "none"
parameters were added to the code chunk to prevent printing of the R code results and the exploratory plots created in the code chunk.
The code chunk options mentioned above have been removed. The output is printed in the rendered report (plot and model output now printed to html report).
```{r lin-reg2, echo = FALSE, eval = TRUE}
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
geom_smooth() +
labs(title = "Relationship between Weight and Miles Per Gallon")
model_lin
```
##
## Call:
## lm(formula = mpg ~ disp + wt, data = mtcars)
##
## Coefficients:
## (Intercept) disp wt
## 34.96055 -0.01772 -3.35083