I need to increase the height of the plot/image generated by knitr with the rmd file (not save the file with dev). I can’t find whether ggplot2 provides a mechanism to adjust the image size. Any ideas?
On 27 Jul 2016, at 13:26, Frank wrote:
I need to increase the height of the plot/image generated by knitr with the rmd file (not save the file with dev). I can’t find whether ggplot2 provides a mechanism to adjust the image size. Any ideas?
Hi Frank,
You can see an example of how to do that here:
https://rstudio.github.io/dygraphs/r-markdown.html
The link is for a certain plotting package (dygraphs), but the instructions work for any plot in rmarkdown documents.
You can set default fig_width
and fig_height
values for the entire rmd document:
---
title: "My Document"
output:
html_document:
fig_width: 6
fig_height: 4
---
or set them for specific chunks.
```{r, fig.width=8, fig.height=4}
ggplot(...)
```
Does this answer your question?
Sherif
Hi Sherif,
Thank you for the solution, which almost solves my problem. To be more specific, I have a number of horizontal bar plots. The height of each plot depends on the number of bars in the plot. It seems I need to specify the plot height in my R code dynamically. Is there an approach to do that?
Thank you,
Frank
I think at this point there are too many clarification questions to ask and you should provide a reproducible example (ideally with a sketch/mockup of what you'd like to see) to help list members help you.
There would also be the question of "why". From what I understand, you would like to have multiple horizontal bar plots (stacked vertically or horizontally?) that vary their height to keep the height of each bar constant. I wonder if that's the best way to visualize whatever it is you want to visualize, and if maybe you should look into facet_grid
or facet_wrap
if you haven't already.
Sherif
Hi Sherif,
You are probably right; I need to rethink the plots.
Thank you,
Frank