如何将维恩图与r中的决策树图合并

时间:2018-03-02 01:09:12

标签: r decision-tree venn-diagram

我试图将维恩图的情节与决策树的情节结合起来,但到目前为止还没有运气。看起来情节不是同一类型,但我无法将它们组合起来,因为我收到错误

下面是一些可重现的代码:

vennPlot <- VennDiagram::draw.pairwise.venn(10000, 7000, 3000, c("First", "Second"), scaled = FALSE)


grid::grid.draw(vennPlot)


library(party)

set.seed(290875)

airq <- subset(airquality, !is.na(Ozone))

airct <- ctree(Ozone ~ ., data = airq, controls = ctree_control(maxsurrogate = 3))


plot(airct, main = "Matched and Unmatched cases applications")


library(grid)

library(gridBase)

library(gridExtra)


layout(matrix(c(1,2), nrow = 1, ncol = 2, byrow = TRUE))


plot(airct, main = "Matched and Unmatched cases applications")


# second base plot 

frame()

# Grid regions of current base plot (ie from frame)

vps <- baseViewports()

pushViewport(vps$inner, vps$figure, vps$plot)

# Table grob

grob <-  grobTree(grid::grid.draw(vennPlot))

grid.draw(grob)

popViewport(3)

1 个答案:

答案 0 :(得分:1)

您似乎尝试使用基本图形绘制ctree对象,但它基于网格,就像来自VennDiagram()的图一样。以下是工作样本。

grid.newpage()
pushViewport(viewport(layout = grid.layout(ncol = 2)))
pushViewport(viewport(layout.pos.col = 1))
plot(airct, main = "Matched and Unmatched cases applications", newpage = FALSE)
popViewport()
pushViewport(viewport(layout.pos.col = 2))
grid::grid.draw(VennDiagram::draw.pairwise.venn(10000, 
                                                7000, 
                                                3000, 
                                                c("First", "Second"), 
                                                scaled = FALSE))
popViewport(0)

enter image description here