简体   繁体   English

安排 R 地块:我怎样才能安排 VIM package 的地块?

[英]arrange R plots: how can I arrange plots of the VIM package?

I would like to generate multiple plots using marginplot() (VIM package) and then arrange them into one big figure.我想使用 marginplot() (VIM 包)生成多个图,然后将它们排列成一个大图。 I tried to use grid.arrange (grid/gridExtra package) and it did not work.我尝试使用 grid.arrange (grid/gridExtra 包),但它不起作用。 The error was, that a grob was expected as input.错误是,一个 grob 应该作为输入。 So I tried to first convert the marginplot into a ggplot (as.ggplot) or grob (as.grob) but this did not work.所以我尝试先将 marginplot 转换为 ggplot (as.ggplot) 或 grob (as.grob) 但这不起作用。 Has anyone an idea how to arrange the plots?有谁知道如何安排情节?

library(VIM)
library(ggplotify)
library(grid)
library(gridExtra)

x <- cars[, c("speed", "dist")]
marginplot(x)
y <- cars[, c("speed", "dist")]
marginplot(y)

p <- qplot(1,1)
#p2 <- as.ggplot(marginplot(x))
r <- rectGrob(gp=gpar(fill="grey90"))
grid.arrange( r, p,p, r, ncol=2)

I created a small code with cars, where I managed to arrange grey squares and qplots.我用汽车创建了一个小代码,在那里我设法安排了灰色方块和 qplots。 put I cannot add the marginplot.把我不能添加marginplot。

With base plots this error occurs.对于基图,会发生此错误。 Learned here: grid.arrange from gridExtras exiting with "only 'grobs' allowed in 'gList'" after update在这里学习: gridExtras 中的 grid.arrange 在更新后以“'gList' 中只允许 'grobs'”退出

grid.arrange is intended to be used with "grid graphical objects" (grobs), such as ggplot2 . grid.arrange旨在与“网格图形对象”(grobs)一起使用,例如ggplot2

One could find an equivalent grid-plot or use a base-graphics approach to stacking plots.可以找到等效的网格图或使用基本图形方法来堆叠图。 Try this:尝试这个:

library(VIM)

x <- cars[, c("speed", "dist")]
y <- cars[, c("speed", "dist")]

par(mfrow = c(2,2))
marginplot(x)
marginplot(y)
plot(rnorm(100))
hist(rnorm(100)) 
par(mfrow = c(1, 1)) #reset this parameter

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM