我有两个图 p1 和 p2,我试图使用 grid.arrage 绘制它们。我的代码如下所示:
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")
Run Code Online (Sandbox Code Playgroud)
但是,当我运行这个时,我看到一个错误"Error in arrangeGrob(...) : could not find function "textGrob"
当我只跑步时grid.arrange(p1, p2, ncol=2),它运行得很好。但没有任何标签和标题。但是,我无法理解我的代码有什么问题。我都尝试过main=...,但top=...都不起作用。
有什么建议么?
这是两个简单的 png 文件。
\n\nvalue <- c(0, 1, 20, 3, 3, 0, 0, 5, 2, 5, 2, 7)\nnames.arg =c("0-15","15-19","20-24","25-29","30-34",\n "35-39","40-44","45- 49","50-54","55-59","60-64","65 Jahre oder \xc3\x84lter")\ndf <- data.frame(names.arg = names.arg, value = value)\n\np1 <- ggplot(df, aes(x=names.arg, y=value)) + geom_bar(stat = "identity")\nsave(p1, file = "p1.png")\n\nvalue2 <- c(0, 1, 20, 3, 3, 0, 0, 5, 2, 5, 2, 7)\nnames2 =c("0-15","15-19","20-24","25-29","30-34",\n "35-39","40-44","45- 49","50-54","55-59","60-64","65 Jahre oder \xc3\x84lter")\ndf2 <- data.frame(names = names2, value = value2)\n\np2 <- ggplot(df2, aes(x=names, y=value)) + geom_bar(stat = "identity", fill = "red")\nsave(p2, file = "p2.png")\nRun Code Online (Sandbox Code Playgroud)\n\n当您将它们组合起来时,top =和bottom =参数可以正常工作:
grid.arrange(p1, p2, ncol=1, top = "Example", bottom = "Sample")\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n根据评论进行编辑
\n\n在通话之外创建标题grid.arrange():
title <- textGrob("Distribution across each day of the week", gp = gpar(fontface = "bold", cex = 1.5))\nRun Code Online (Sandbox Code Playgroud)\n\n并修改调用:
\n\ngrid.arrange(p1, p2, ncol=1, top = title, bottom = "Sample")\nRun Code Online (Sandbox Code Playgroud)\n\n\n
| 归档时间: |
|
| 查看次数: |
13019 次 |
| 最近记录: |