Arrange multiple plots into a grid

There are two avalaible options to arrange ggiraph outputs into a grid. As ggiraph is mainly only new geoms, package cowplot and patchwork can be used seamlessly.

Using cowplot

Mouseover points to see where they are located in the other graph.

girafe( code = print(gg1 + gg2), width_svg = 8, height_svg = 4)

Using patchwork

Mouseover points to see where they are located in the other graph.

girafe( code = print(gg1 + gg2), width_svg = 8, height_svg = 4)

Dynamic dendrogram

expr.R

##         col_4    col_5    col_6    col_7    col_8    col_9
## id_1 3.943339 3.885332 3.972568 3.897985 3.968078 3.840585
## id_2 2.405950 2.364125 3.035228 2.581442 2.476972 2.755192
## id_3 1.845634 1.876945 2.006225 1.917262 2.001037 1.979254
## id_4 3.032080 2.923366 3.011424 3.049322 3.158107 3.008166

First compute data for dendrograms

Create a data.frame from the matrix, then order.

Add a variable to have tooltips as tables

## # A tibble: 6 x 4
##   gene  variable measure tooltip                                          
##   <fct> <fct>      <dbl> <chr>                                            
## 1 id_8  col_22      4.21 <table><tr><td>gene</td><td>id_8</td></tr><tr><t…
## 2 id_8  col_20      3.87 <table><tr><td>gene</td><td>id_8</td></tr><tr><t…
## 3 id_8  col_25      3.87 <table><tr><td>gene</td><td>id_8</td></tr><tr><t…
## 4 id_8  col_44      3.27 <table><tr><td>gene</td><td>id_8</td></tr><tr><t…
## 5 id_8  col_45      3.72 <table><tr><td>gene</td><td>id_8</td></tr><tr><t…
## 6 id_8  col_33      3.38 <table><tr><td>gene</td><td>id_8</td></tr><tr><t…

Create the ggplot using geom_tile_interactive

p <- ggplot(data = expr_set, aes(x = variable, y = gene) ) +
  geom_tile_interactive(aes(fill = measure, tooltip = tooltip), colour = "white") +
  scale_fill_gradient(low = "white", high = "#BC120A", limits = c(0, 13)) +
  geom_segment(
    data = data_c,
    mapping = aes(x = x, y = yend, xend = xend, yend = y),
    colour = "gray20", size = .2) +
  geom_segment(
    data = data_r,
    mapping = aes(x = x_, y = y_, xend = xend_, yend = yend_),
    colour = "gray20", size = .2) +
  coord_equal()

Theme the object

p <- p + theme_minimal() +
  theme(
    legend.position = "right",
    panel.grid.minor = element_line(color = "transparent"),
    panel.grid.major = element_line(color = "transparent"),
    axis.ticks.length   = unit(2, units = "mm"),
    plot.title = element_text(face = "bold", hjust = 0.5, size = 12),
    axis.title = element_text(size = 9, colour = "gray30"),
    axis.text.y = element_text(hjust = 1, size = 5, colour = "gray40"),
    axis.text.x = element_text(angle = 90, hjust = 1, size = 5, colour = "gray40"),
    legend.title=element_text(face = "bold", hjust = 0.5, size=8),
    legend.text=element_text(size=6)
  )

Use girafe

girafe(ggobj = p, width_svg = 8, height_svg = 6)