我想将来自 DiagrammeR 的图表包含在一个多面板图中,例如来自 ggplot2,但不幸的是,DiagrammeR 没有在图形设备上写入。有谁知道这是怎么做到的吗?
这是我的示例,它适用于两个 ggplot2 图表,但当我将它与 DiagrammeR 结合使用时就不行了。
library(ggplot2)
library(DiagrammeR)
library(grid)
library(gridExtra)
set.seed(1)
x <- 1:10
y <- x*rnorm(n=10, mean = 1, sd = 0.2)
data <- data.frame(x,y)
plot <- ggplot(data, aes(x=x,y=y)) + geom_point()
plot1 <- arrangeGrob(plot, top = textGrob("A", x = unit(0.0, "npc"), y =
unit(1, "npc"), just=c("left","top"), gp=gpar(col="black", fontsize=14,
fontfamily="Times")))
plot2 <- arrangeGrob(plot, top = textGrob("B", x = unit(0.0, "npc"), y =
unit(1, "npc"), just=c("left","top"), gp=gpar(col="black", fontsize=14,
fontfamily="Times")))
grid.arrange(plot1, plot2)
d <- grViz("
digraph boxes_and_circles {
# add node statements
node [shape = box]
A; B
node [shape = box]
C; D
A->C; B->D
}
")
d
d <- arrangeGrob(d, top = textGrob("B", x = unit(0.0, "npc"), y = unit(1,
"npc"), just=c("left","top"), gp=gpar(col="black", fontsize=14,
fontfamily="Times")))
grid.arrange(plot1, d)