2

我想知道是否有一种方法可以在一页上安排 Gmisc 包的多个漂亮的过渡图(例如两个彼此相邻或两个两个)?我尝试了各种常见的方法(例如par(mfrow = c(2,2))grid.arrange()),但到目前为止都没有成功。我将不胜感激任何帮助。谢谢!

library(Gmisc)

data.1 <- data.frame(source = c("A", "A", "A", "B", "B", "C", "C"),
                     target = c("A", "B", "C", "B", "C", "C", "C"))
data.2 <- data.frame(source = c("D", "D", "E", "E", "E", "E", "F"),
                     target = c("D", "E", "D", "E", "F", "F", "F"))

transitions.1 <- getRefClass("Transition")$new(table(data.1$source, data.1$target), label = c("Before", "After"))
transitions.2 <- getRefClass("Transition")$new(table(data.2$source, data.2$target), label = c("Before", "After"))

# wish to render transition 1 and transition 2 next to each other
transitions.1$render()
transitions.2$render()
4

1 回答 1

1

这实际上是 1.9 版本之前的一个错误(在编写本文时上传到 CRAN,现在可从 GitHub 获得)。您需要做的是使用grid::viewport系统:

library(grid)
grid.newpage()
pushViewport(viewport(name = "basevp", layout = grid.layout(nrow=1, ncol=2)))
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 1))
transitions.1$render(new_page = FALSE)
popViewport()
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 2))
transitions.2$render(new_page = FALSE)

在此处输入图像描述

于 2019-07-07T20:05:14.093 回答