3

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?

Gorka
  • 3,555
  • 1
  • 31
  • 37

1 Answers1

5

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

Willian Vieira
  • 211
  • 2
  • 6
  • 2
    Awesome answer, very useful info when plotting decision trees with the igraph "layout_as_tree". You saved me a lot of source code digging – Gabe Church May 09 '19 at 20:33