r - gList中仅允许使用杂项

标签 r plot gridextra

全部-关于这个确切的主题还有其他几个问题,但是没有一个问题可以解决我所面临的问题。这是一个简单的代码片段。谁能告诉我这里的问题是什么?

> grid.arrange(plot(rnorm(1000)),hist(rnorm(1000)), nrow=2, ncol=1)
Error in gList(list(wrapvp = list(x = 0.5, y = 0.5, width = 1, height = 1,  :
  only 'grobs' allowed in "gList"

最佳答案

问题在于plot()hist()是基本图形,而不是网格或ggplot图形,因此它们不是杂项(“grob”是“grid图形对象”的缩写,有些怪异)。您可以找到等效的网格图,也可以使用基本的图形方法来堆叠图。

后者的处理方式:

> par(mfrow = c(2, 1))
> plot(rnorm(1000))
> hist(rnorm(1000)) #are you sure you want to make a hist of 1000 *different* random numbers?
> par(mfrow = c(1, 1)) #reset this parameter

输出:

enter image description here

您也可以考虑使用layout。键入?layout以获得详细信息。

关于r - gList中仅允许使用杂项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42742815/

相关文章:

r - 关于使用 rvest 和 purrr 抓取带有嵌套链接的多个页面的问题

r - 如何告诉 R 在 Windows 中使用代理自动配置脚本 (PAC)

python - 在 R 中使用 python 虚拟环境

python - 如何从 csv 文件中提取特定列并使用 python 绘图

R:Shiny - 无功输出在 grid.arrange(from gridExtra) 中不起作用

r - 拆分数据框值并放入 R 中的一组?

python - Matplotlib 热图 : Image rotated when heatmap plot over it

matlab - 绘制矢量时绘制点 : Matlab

r - 我如何摆脱 arrangeGrob 中的随机背景网格

R grid.arrange : nrow * ncol >= n is not TRUE