I am trying to create a plot in R and use knitr and latex to print that plot to a pdf. I think I am taking the correct steps: 1. save plot as .png in same folder as .tex file 2. write this into the latex file as includegraphics 3. run the knitr
However, the program is not recognizing/finding my recently created plot .png even though I checked that it is there in explorer.
This is my code in R to create the .png that seems to successfully create the .png file in my working directory (which is also where the .tex file is):
png("hab_pie.png", height=400, width=400)
bp <- ggplot(aoi_HabTerr2, aes(x="", y=acres, fill=habitat)) + geom_bar(width=1, stat="identity")
bp + coord_polar("y", start=0)
dev.off()
This is the relevant code that is in my .Rnw document:
\documentclass{article}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{fancyhdr} %for headers,footers
\usepackage{underscore} %needed if any text has underscores
\usepackage[utf8]{inputenc}
\usepackage[singlelinecheck=false]{caption}
\geometry{letterpaper, top=0.45in, bottom=0.75in, left=0.75in, right=0.75in}
\begin{document}
\includegraphics[width=\linewidth]{hab_pie}
\end{document}
I am getting this error:
LaTeX Error: File `hab_pie' not found.
And when I look in the folder, the file is present under the same name:

.Rnwextension (2) insert after "Hello" some working R code (e.g.2+3) delimited between lines with<<>>=and@(4) Open it with Rstudio and push the "Compile" button. Finish. You should have already a PDF with the R ouput, in this case, with "Hello" and the result of the sum (5). The same if the R code is a plot. BTW, better use PDF formats (not PNG) for the R graphs in a LaTeX document. – Fran Sep 11 '17 at 23:24_? Which tex engine do you use to compile?pdflatexor something else? – samcarter_is_at_topanswers.xyz Sep 12 '17 at 12:50knitrare (1) literate programing: the same file is able to R programming and typesetting the results and discuss them. It can manage a entire book about statistics without problem (2) reproducible research: with the source file, anyone can trace how everything was exactly done, and more important (3) save your time: free you from include/update manually the results and make mistakes doing this.;)– Fran Sep 12 '17 at 17:44