我想在多面板图中包含来自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)