- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将两个图形对象 ( grob
) 组合成一个图 - 其中一个使用“标准 ggplot()
”调用创建,另一个使用 grid.draw()
创建在 ggplot_gtable
上对象 ( based on this thread )。
library(ggplot2)
library(grid)
library(gridExtra)
plot_gtable <- function(x) {
grid::grid.draw(ggplot_gtable(ggplot_build(x)))
}
plot1 <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
plot2 <- plot_gtable(ggplot(mtcars, aes(mpg)) + geom_dotplot())
grid.arrange(plot1, plot2)
Error in gList(structure(list(wrapvp = structure(list(x = structure(0.5, class = "unit", valid.unit = 0L, unit = "npc"), : only 'grobs' allowed in "gList"
由 reprex package 创建于 2018-12-12 (v0.2.1)
显然,调用 grid.draw
结果 NULL
对象,不是 grob
,这似乎是为什么 grid.arrange()
的原因在这种情况下失败。
我尝试过调用和不调用 grid::grid.newpage
第一的。
我尝试使用 grid::viewport
和 gridExtra::arrangeGrob
和 ggpubr::ggarrange
和 cowplot::plot_grid
还有patchwork
包裹,一切都无济于事。
如何使用这些对象创建组合图?
最佳答案
当使用 grid.arrange
组合绘图和/或 grob 时,您希望使用实际对象而不是尝试绘制它。这就是为什么 plot2
是 NULL
的原因,因为它是绘制的而不是返回的,因此不能组合。所以在组合地 block 之前不要画它。
library(ggplot2)
library(gridExtra)
# example ggplot
plot1 <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
# example gtable
plot2 <- ggplotGrob(plot1)
grid.arrange(plot1, plot2)
关于r - 组合两个 grobs ,其中一个是使用 grid.draw 创建的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53742970/
我很惊讶以下从颜色向量创建的简单 grob 几乎按要求工作。 但是,我想让渐变从左到右,而不是从上到下。 library(ggplot2) library(grid) grad = colorRamp
我需要将 R 基础图转换为 grob,以便它可以叠加在一些 ggplot 上s。 我发现有几个函数可以做到这一点,ggplotify::as.grob和 cowplot::plot_to_gtable
我试图在 ggplot2 中生成一个轴线中断(轴线上有一个白色段),但遇到了一些问题。 使用信息性帖子 annotate-ggplot-with-an-extra-tick-and-label我能够在
这是 this question 的后续问题. OP 要求一种方法以特定距离安排地 block 的一部分。我认为 teunbrand 给出了一个很好的答案。 我自己的建议(用cowplot提取图例,并
披露:我不确定如何为这个问题制作一个可重现的示例。 我正在尝试使用gridExtra包绘制一个GROB列表。 我有一些代码,如下所示: ## Make Graphic Objects for Spec
我正在尝试绘制一个热图以及一行树状图,我对其进行了操作(修剪了分支数量),并使用grid.draw进行了对齐. 这是我的数据: set.seed(10) mat <- matrix(rnorm
我有一个 ggplot 对象: ggplot(plot1,aes(x = c, y = value, colour = variable, linetype = variable,size = var
所以我试图制作一个 grob 列表,然后将它们传递给 grobTree() ,但我的列表项不会被 do.call() 读入. 这是我的代码: library(purrr) library(grid)
我在画几个ggplot2对象并将它们放在 grid.arrange 上在对“pdf”设备的调用中。我发现如果我先对绘图进行光栅化,PDF 的性能会提高大约 10 亿倍(生成速度更快,渲染速度更快)。所
我有一个非常大的两个类别的散点图,其中一个点是“命中”。我想在图的顶部和侧面绘制直方图来表示在以下网站上看到的点击:http://blog.mckuhn.de/2009/09/learning-ggp
我正在尝试使用 ggplot2 重现以下 [base R] 图 我已经解决了大部分问题,但目前让我感到困惑的是将连接位于图右侧的边缘地毯图的线段放置在各自的标签上。标签是通过 anotation_cu
我正在尝试使用 grid.arrange 组合多种类型的图形/表格,其中之一是使用 corrplot 的相关矩阵。有没有办法将 corrplot 转换为 grob 或导出/导入为与 grid.arra
给定一个 ggplot,例如点,您如何找出给定点对应的数据行? 示例图: library(ggplot2) (p 为了回答 kohske 关于我为什么要这样做的问题,我使用 gridSVG 创建交互
我正在尝试使用 grid.arrange 组合多种类型的图形/表格,其中之一是使用 corrplot 的相关矩阵。有没有办法将 corrplot 转换为 grob 或导出/导入为与 grid.arra
如何在不一直使用 annotation_custom 的情况下在 ggplot 图表中包含多个 grobs 对象? 这是我的代码: df <- data.frame(x = 1:10, y = 1:1
如果对象包含我希望在分配时解析的其他变量,那么将 ggplot2 grob 分配给变量的正确方法是什么。 例如: xpos和 ypos是我想要解决的值。 我将 geom_text 分配给 ptext,
更新原来是无法通过远程桌面连接生成光栅图形的问题。 我想将文件中的图像插入到使用 ggplot2 绘制的绘图中。这个问题已经在这里问过(Inserting an image to ggplot2),但
我很难找到对齐 ggplot grob 和 table grob 的解决方案。我试图按照说明here但仍然没有给出我想要的结果。 library(grid) library(gridExtra) li
R 图形具有 grid 包,理论上允许使用 grid.curve 在形状之间创建弯曲箭头(请参阅此处的 grid.curve 描述 https://www.stat.auckland.ac.nz/~p
在对齐网格图形对象时遇到了一些麻烦——我已经阅读了我能找到的所有文档,包括 Murrell 的书,但没有成功。我认为我正在尝试做的事情非常简单,所以希望我缺少简单的东西。 这是一个可重现的示例,它将按
我是一名优秀的程序员,十分优秀!