first up, it is my first coding assignment and I am already desperate. I downloaded the latest version of Rstudio for Mac 3 days ago and I am now trying to submit an assignment in word format that displays graphs about life expectancies. When I run the code in Rstudio, the plot is shown correctly. However, once I knitr it to html or other formats, it only shows the code, not the graphs. Below, you can see what I did.
This is just copied out of my Rstudio session. Most of it was already given and I just had to put in the aesthetics etc. I tried to find an answer online, and sometimes I thought I found the correct thread, but then technical terms made it impossible for me to understand, as I started R just 3 days ago. So, I would be very greatful for an easy explanation. If you require any further information, I will try to provide it.
Thanks.
The forum's homework policy encourages us to not simply give you fixed code, but help you get there yourself:
In your case, I'd first see if this is an issues with RMarkdown in general, or with your code. If you create a new markdown and use the default sample that's given, can you generate the plots once you knit it? If not, there's an issue with R-studio/R, if you can, it's your code.
In your code, look at the plot1 line. If you run it as you put it above, I get an error:
Error: Don't know how to add print(plot1) to a plot
The error message pretty much gives you the fix for the issue, but I doubt this was your original issue as you wouldn't have been able to plot it locally in R with that error either. If I fix it, my R-markdown works.
One last tip: Click on the options button on the top right of your code chunk to check if you are rendering both code and output