Plots not showing up on HTML file after running in Rmarkdown

Viewed 1343

When I generate plot in Rmarkdown, it shows up under Plots in Rstudio but does not include it when I knit it. How can I include the plot in the markdown?

I also have "Create a standalone HTML document" checked and similarly plots don't show up in that standalone HTML document.

e.g. I run this code in Rmarkdown file but plot does not stay in the knitted document.

boxplot(bwt ~ smoke, data=birthwt,
        xlab = "drivetrain (0 = don't smoke, 1 = smoke)",
        ylab = "birth wt. in g",
        main = "birth weight vs smoking status",
        pch = 20,
        cex = 2,
        col = "darkslategray",
        border = "goldenrod3")

Please advise.

1 Answers

It does work in the following small snippet of RMD

---
title: "testing"
author: "akrun"
date: "10/05/2021"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(MASS)
data(birthwt)
boxplot(bwt ~ smoke, data=birthwt,
        xlab = "drivetrain (0 = don't smoke, 1 = smoke)",
        ylab = "birth wt. in g",
        main = "birth weight vs smoking status",
        pch = 20,
        cex = 2,
        col = "darkslategray",
        border = "goldenrod3")

```

-output

enter image description here

Related