Search code examples
rggplot2widthknitrresolution

Is there a way of increasing resolution and width of ggplots when knitting an R script without writing it in R Markdown?


I have a plain R script, not written using R Markdown. In it I create several graphs using ggplot. I then knit the script via File > Knit Document.

I have two problems with the output. First, the plots are not as wide as the rest of the output. Second, the resolution of the plots is not very good.

Is there any way I can increase the width and resolutions of the graphs without having to rewrite the script using R Markdown?


Solution

  • You can use the knitr spin syntax to provide chunk options for your plots. This should increase their width (and probably also fix the resolution issue):

    #+ fig.width = 3
    plot(1) # narrow plot
    
    #+ fig.width = 9
    plot(1) # wide plot