Graph of subtle changes after using markdown knitr

Using the knitr and markdown packages to weave markdown Rmd files and then html causes unexpected behavior in how ggplot2 graphics appear in the final html file.

For example, using the following Rmd diamond.Rmd file

 # ggplot2 graph shows up fainter, and text smaller ```{r echo=FALSE, message=FALSE, warning=FALSE} opts_chunk$set(fig.width=18, fig.height=10) require(ggplot2) ``` *** # Simple Plot ```{r echo=FALSE, message=FALSE, warning=FALSE} data(diamonds) g <- ggplot(diamonds, aes(carat, depth, colour=color)) + geom_point() + facet_wrap(~cut) g ``` 

with this file knit.R

 require(markdown) require(knitr) knit('diamonds.Rmd') markdownToHTML('diamonds.md', 'diamonds.html', options=c('base64_images')) browseURL(paste('file://', file.path(getwd(), 'diamonds.html'), sep='')) 

I made a screeenshot of the plot in an html file and included it below (is there a better way to show this?):

plot from html file

The plot inside the html file is easier, i.e. the color is darker. In addition, the text on the graph, including axis labels and label labels, is smaller and lighter, making them very difficult to read.

If you look at a graph created directly from R, you will see that it does not have these problems.

plot directly from R

I assume this is a problem with my graphics device or a graphics device that uses knitr.

Is there a way to force the graphics that end up in the html file to preserve the original look of the graphic, i.e. stay darker and have more text?

+7
source share
1 answer

As suggested by @Ramnath:

If you want to keep the same shape size, but with a higher pixel size, use:

fig.width = 9, fig.height = 5, dpi = 144

By default, dpi is 72, this will give you a graph of the same size, but with large pixels and text.

+4
source

All Articles