Error in grid.arrange - arrangeGrob() function

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

I have two plots p1 and p2 which I am trying to plot using grid.arrage. My code looks as below:

grid.arrange(p1, p2, ncol=2,     top = textGrob("Distribution across each day of the week",      gp = gpar(fontface = "bold", cex = 1.5)),     bottom = "Day of the week") 

However, when I run this, I am seeing an error "Error in arrangeGrob(...) : could not find function "textGrob"

When I run only grid.arrange(p1, p2, ncol=2), it runs fine. But without any labels and title. However, I couldnt understand what is the problem with my code. I tried both main=... and as well as top=... Neither of them works.

Any suggestions?

回答1:

Here are two simple png files.

When you combine them, the top = and bottom = arguments work fine:

grid.arrange(p1, p2, ncol=1, top = "Example", bottom = "Sample") 

EDIT BASED ON COMMENT

Create the title outside of the grid.arrange() call:

title <- textGrob("Distribution across each day of the week", gp = gpar(fontface = "bold", cex = 1.5)) 

and revise the call:

grid.arrange(p1, p2, ncol=1, top = title, bottom = "Sample") 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!