[英]Plot list of plots in GGiraph
I am trying to plot a list of plots using GGiraph in Rstudio.我正在尝试 plot 在 Rstudio 中使用 GGiraph 的情节列表。 The solution to plot multiple plots is either through Cowplot (
ggobj = plot_grid(plot1, plot2)
) or Patchwork ( code = print(plot / plot)
). plot 多图的解决方案是通过 Cowplot (
ggobj = plot_grid(plot1, plot2)
) 或 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?有人对此有解决方案吗?
You could try the plotlist
argument in plot_grid
.您可以尝试
plot_grid
中的plotlist
参数。
#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))
You can also do this with functional assembly in patchwork
, using the wrap_plots()
function and the ncol
or nrow
arguments.您也可以使用
wrap_plots()
function 和ncol
或nrow
arguments 在patchwork
中进行功能组装。 wrap_plots()
can take either a series of graphs or a list. wrap_plots()
可以采用一系列图形或列表。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.