1
votes

I am a new R user and am working with an Rmarkdown document and knitr.

I have code that works in RStudio, where I generate 4 scatterplots and put them into a 2x2 figure. See this image for what it should look like in the word document: R plots

When I put this code into Rmarkdown, the document runs, looks great for everything except these scatterplots, but the code is not converted to the figure (like it does in R).

This section of Rmarkdown:

```{r echo=FALSE
par(mfrow=c(2,2))
plot(ICEstata.dat$ice_income, ICEstata.dat$imr2010_14, main="ICE_Income and IMR2010-2014", 
     xlab="ICE_Income", ylab="IMR_2010-14", 
     xlim=c(-1, 1), ylim=c(0, 25), pch=19)

plot(ICEstata.dat$ice_race, ICEstata.dat$imr2010_14, main="ICE_Race and IMR2010-2014", 
     xlab="ICE_Race", ylab="IMR_2010-14", 
     xlim=c(-1, 1), ylim=c(0, 25), pch=19)

plot(ICEstata.dat$ice_combined, ICEstata.dat$imr2010_14, main="ICE_Combined and IMR2010-2014", 
     xlab="ICE_Combined", ylab="IMR_2010-14", 
     xlim=c(-1, 1), ylim=c(0, 25), pch=19)

with(ICEstata.dat, plot(ICEstata.dat$hhindex, ICEstata.dat$imr2010_14, main="Hardship and IMR2010-2014",  xlab="Hardship", ylab="IMR_2010-14", pch=19, axes=F))
axis(2)
axis(1, at=c(20, 40, 60, 80), labels=c(80, 60, 40, 20))
box()
}`

When I knit and it goes into the word document, everything gets printed in the document, including ```{r echo=FALSE at the beginning of the code. I need the figure with the 2x2 plots to show up in the document produces, but am unsure If I am doing it the right way or if there is a more efficient way of going about this. The way I see it, either: 1). I need to use a different R procedure to do this or 2). I need to use different code in Rmarkdown.

I am open to either of these (or any other ideas for that matter).
Thank you in you advance for your time.

1

1 Answers

1
votes

The opening line of your code chunk is missing the closing brace. It should look like

```{r echo=FALSE}

and the last line should look like

```