Why does a ggplot look slightly different in rstudio compared to markdown?

Is this to do with graphic devices??

Yes, exactly. If you look closely enough, png, pdf and svg are slightly different also.

1 Like

Thanks @technocrat

Is there a way to make markdown ggplot outputs look exactly the same as what I see in the Rstudio IDE?

I have the global options for graphics device set to Default

I guess I have to ask for a definition of "exactly". Here is a composite of the plot window saved as pdf on top and the markdown pdf on bottom. I had to very slightly widen the margins for the first version. What other differences do you see that are important?

1 Like

You can control graphics devices and other related parameters in your R Markdown document with knitr options:

There's also the full list of knitr options related to plots in the knitr docs.

n.b. If you're using Quarto, knitr chunk and global options still work, the native Quarto syntax is just a little bit different (uses underscores instead of periods)


Thanks @mara and @technocrat

I have noticed that very thin lines look different between my Default graphics device and the Cairo/agg devices.

I'm wondering if there are recommendations about what to use. I've added this as a seperate question

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.