Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize RMarkdown page to fit a big plot (non-rescaled igraph)

I need to fit a big igraph plot in an RMarkdown document, but a lot of the nodes and labels overlap (in a way similar to the image below).

enter image description here

I figured using the 'rescale=FALSE' argument could work, but then the problem is that the plot size is bigger than the page size, regardless of the fig.height, fig.width options.

enter image description here

Below you can see a reproducible example (save as .Rmd and Knit):

---
output: pdf_document
---

# How to resize page to fit plot?
```{r pressure, echo=FALSE, fig.height=20, fig.width=20, message=FALSE, warning=FALSE}
library(igraph)
st <- make_star(500)
set.seed(100)
plot(st, vertex.size=10, vertex.label=NA, rescale=FALSE) 
```

There is a way to adjust the page size to a non-rescaled igraph?

like image 957
Gorka Avatar asked Nov 25 '25 09:11

Gorka


1 Answers

You can adjust the page size by adding the classoption in the YAML.

But you can also play around with the fig size and the xlim() and ylim() to adjust the figure inside the page as answered here.

---
output:
  pdf_document:
documentclass: article
classoption:
  - a1paper
---

# How to resize page to fit plot?
```{r pressure, echo=FALSE, fig.height=30, fig.width=40, message=FALSE, warning=FALSE}
library(igraph)
st <- make_star(500)
set.seed(100)
plot(st, vertex.size=10, ylim=c(3,5), xlim = c(-7, 15),vertex.label=NA, rescale=FALSE)
```

enter image description here

like image 69
Willian Vieira Avatar answered Nov 27 '25 22:11

Willian Vieira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!