Figures

Figures are also a highlight of R Markdown. Plots are a fantastic way of communicating data and I would definetly encourage you to learn the basics of ggplot, if you have not already. You can now just implement a ggplot in the code chunk.

library(ggplot2) # For ggplot
library(gridExtra) # For arrangement of two figures in one row

f1 <- ggplot(output, aes(x = sml.rsq)) +
  geom_histogram(binwidth = 0.01) +
  geom_vline(xintercept = final.model$rsq[200], color = "orange2", linetype = 2)+
  xlab(expression(R^{2})) +
  ylab("Number of samples")

f2 <- ggplot(output, aes(x = sml.mse)) +
  geom_histogram(binwidth = 0.08) +
  geom_vline(xintercept = final.model$mse[200], color = "cornflowerblue", linetype = 2)+
  xlab("MSE") +
  ylab("Number of samples")

grid.arrange(f1, f2, ncol = 2)
Non parametric density functions for $R^2$ and MSE with 1,000 Monte Carlo iterations. \label{name}

Figure 2: Non parametric density functions for \(R^2\) and MSE with 1,000 Monte Carlo iterations.

For captions and labeling figures, I used {r, fig.height=3, fig.cap = "Your text here. \\label{name}"} on top of the code chunk. The plot then can be referenced in the text with \ref{name}.