grid.arrange中的错误 - arrangeGrob()函数 [英] Error in grid.arrange - arrangeGrob() function

查看:898
本文介绍了grid.arrange中的错误 - arrangeGrob()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个图p1和p2,我试图用grid.arrage进行绘图。我的代码如下所示:

  grid.arrange(p1,p2,ncol = 2,
top = textGrob 每周的每一天分配,
gp = gpar(fontface =bold,cex = 1.5)),
bottom =星期几)

然而,当我运行这个时,我看到错误在arrangeGrob(...)中出现错误:找不到函数textGrob



当我只运行 grid.arrange(p1,p2,ncol = 2 ),它运行良好,但没有任何标签和标题,但是我不明白我的代码有什么问题,我尝试了 main = ... 以及 top = ... 它们都不可用。



有什么建议? / p>

解决方案

以下是两个简单的png文件。

  value <-c(0,1,20,3,3,0,0,5,2,5,2,7)
names.arg = c(0-15 ,15-19,20-24,25-29,30-34,
35-39,40-44,45-49, 54\" , 55-59, 60-64, (df,aes(x = 65),或者是a,b,b,b,b, names.arg,y = value))+ geom_bar(stat =identity)
save(p1,file =p1.png)

value2 < - c(0, 1,20,3,3,0,0,5,2,5,2,7)
names2 = c(0-15,15-19,20-24,25 -29,30-34,
35-39,40-44,45-49,50-54,55-59,60-64 65 Jahre oderÄlter)
df2< - data.frame(names = names2,value = value2)

p2 < - ggplot(df2,aes(x = names,y = value))+ geom_bar(stat =identity,fill =red)
save(p2,file =p2.png)

当您合并它们时, top = bottom = 参数工作正常:

  grid.arrange(p1,p2,ncol = 1,top =Example,bottom =样本)



基于评论编辑



创建 grid.arrange()调用之外的标题:

  title <  -  textGrob(每周的每一天的分布,gp = gpar(fontface =bold,cex = 1.5))

并修改调用:

  grid.arrange(p1,p2,ncol = 1,  $ b 


$> stack.imgur.com/ZuWx8.pngrel =nofollow noreferrer>


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?

解决方案

Here are two simple png files.

value <- c(0, 1, 20, 3, 3, 0, 0, 5, 2, 5, 2, 7)
names.arg =c("0-15","15-19","20-24","25-29","30-34",
             "35-39","40-44","45- 49","50-54","55-59","60-64","65 Jahre oder Älter")
df <- data.frame(names.arg = names.arg, value = value)

p1 <- ggplot(df, aes(x=names.arg, y=value)) + geom_bar(stat = "identity")
save(p1, file = "p1.png")

value2 <- c(0, 1, 20, 3, 3, 0, 0, 5, 2, 5, 2, 7)
names2 =c("0-15","15-19","20-24","25-29","30-34",
             "35-39","40-44","45- 49","50-54","55-59","60-64","65 Jahre oder Älter")
df2 <- data.frame(names = names2, value = value2)

p2 <- ggplot(df2, aes(x=names, y=value)) + geom_bar(stat = "identity", fill = "red")
save(p2, file = "p2.png")

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")

这篇关于grid.arrange中的错误 - arrangeGrob()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆