I'm working on a R markdown file which is almost working completely fine. Most of the outputs including images are shwing up fine when rendering the HTML file with Ctrl+Shift+K. But I'm having issues just with one image, specifically, the image plotted from a Neural Network.
For example, on my file: README.Rmd I have:
set.seed(222)
nn <- neuralnet(score ~ ., data = ds_trn_noc, hidden = 2, err.fct = "sse")
plot(nn)
If I copy the commands above directly on the console, I get the image as expected, which is:
I'm assuming you are using the neuralnet package here — it's really helpful if you can at least include sample code with library() calls in questions like this, since there are a lot of packages out there and many of them have similarly named functions! Even better is a self-contained reproducible example.
It seems like the plot.nn method in the neuralnet package was not written with non-interactive use in mind, so it doesn't entirely play nicely with how knitr captures plot output.
I suspect that the root of the problem is this bit, from the plot.nn documentation:
rep
repetition of the neural network. If rep="best", the repetition with the smallest error will be plotted. If not stated all repetitions will be plotted, each in a separate window.
(By the way, this is one example of how one might go about creating a self-contained, reproducible example for this question . For the model object line, I just used one of the examples from the neuralnet documentation.)
If you need to include more than just the "best" repetition, I think you'll need to save the plot outputs to file using the file argument to plot.nn and then include the images with knitr::include_graphics().
You might also consider submitting a feature request to the GitHub issue tracker for neuralnet to see if the developer is interested in implementing better support for plotting inside R Markdown documents.