r - 在网格中排列 8 个图和一个图例

标签 r plot ggplot2 gridextra cowplot

我有 8 个图和一个图例,我想将它们排列在 3x3 网格中,以便所有轴对齐。

当我不将图例添加到我的网格时,它工作得很好,但是一旦我添加了图例,我的图就会移动并且不再对齐。

plot_grid(SiO2TiO2, SiO2Al2O3, SiO2FeO, SiO2MgO, SiO2CaO, SiO2Na2O, SiO2K2O, SiO2P2O5, align=c("hv"),nrow = 3, ncol = 3)

在没有图例的 3x3 网格中对齐的图:

plot_grid(SiO2TiO2, SiO2Al2O3, SiO2FeO, SiO2MgO, SiO2CaO, SiO2Na2O, SiO2K2O, SiO2P2O5, legend, align=c("hv"),nrow = 3, ncol = 3)

Warning messages:

1: In align_plots(plotlist = plots, align = align) : Graphs cannot be vertically aligned. Placing graphs unaligned.

2: In align_plots(plotlist = plots, align = align) : Graphs cannot be horizontally aligned. Placing graphs unaligned.

图未在带有图例的 3x3 网格中对齐:

有人知道如何将图例与情节对齐吗? 提前致谢!

最佳答案

也许您必须在 grid.arrange 命令中定义绘图的宽度。

就像下面的例子:

plot_grid(SiO2TiO2, SiO2Al2O3, SiO2FeO, SiO2MgO, SiO2CaO, SiO2Na2O, SiO2K2O, SiO2P2O5, legend, align=c("hv"), nrow = 3, ncol = 3, widths=c(2.3, 2.3, 2.3))

关于r - 在网格中排列 8 个图和一个图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44736407/

相关文章:

r - 使用 R 查找总和为给定值的元素

r - 在向量中寻找峰值

python - 如何提取 pandas 数据框中的元组值以使用 matplotlib?

python - 使用颜色条时如何保持图像大小?

graph - Mathematica ListPlot 中的白色区域

r - 创建一个区域图,其中每个区域均匀填充实际点数?

r - 按行索引(数据的原始顺序)而不是按字母顺序设置 ggplot 中 x 或 y 的顺序

r - 堆积条形图上的单个误差条 ggplot

r - 如何在 R 中启动新的图形窗口和/或图形页面

r - 将参数传递给函数以使用 ggplot stat_function 进行绘图