Anders Eriksson
Anders Eriksson

Reputation: 53

Plot list of plots in GGiraph

I am trying to plot a list of plots using GGiraph in Rstudio. The solution to plot multiple plots is either through Cowplot (ggobj = plot_grid(plot1, plot2)) or Patchwork (code = print(plot / plot)). This works if you individually print single plots. However, it looks like it does not accept a list of plots. I want the plots to be arranged in one column with multiple rows.

Does anyone have a solution to this?

Upvotes: 4

Views: 670

Answers (2)

Steffi LaZerte
Steffi LaZerte

Reputation: 88

You can also do this with functional assembly in patchwork, using the wrap_plots() function and the ncol or nrow arguments. wrap_plots() can take either a series of graphs or a list.

library(ggiraph)
library(ggplot2)
library(patchwork)

# Demo figure
g <- ggplot(data = mpg, aes(x = cyl, y = hwy, color = class,
                            tooltip = model, data_id = model)) +
  geom_point_interactive()

# Use wrap_plots from patchwork
g <- wrap_plots(list(g, g), ncol = 1)
girafe(ggobj = g)

Upvotes: 1

Ryan SY Kwan
Ryan SY Kwan

Reputation: 496

You could try the plotlist argument in plot_grid.

#Using the example from giraffe
library(ggiraph)
library(ggplot2)

dataset <- mtcars
dataset$carname = row.names(mtcars)

gg_point = ggplot( data = dataset,
    mapping = aes(x = wt, y = qsec, color = disp,
    tooltip = carname, data_id = carname) ) +
  geom_point_interactive() + theme_minimal()

#using the plotlist argument
library(cowplot)
girafe(ggobj = plot_grid(plotlist=list(gg_point, gg_point), ncol=1))

Upvotes: 2

Related Questions