[英]How to combine a Venn diagram with a decision tree plot in r
I am trying to combine a plot of a Venn Diagram with a plot of a decision tree but so far no luck.我试图将维恩图的情节与决策树的情节结合起来,但到目前为止还没有运气。 It seems the plots are not of the same type but I am not able to combine them, since I get an error似乎这些图的类型不同,但我无法将它们组合起来,因为我收到错误
Below is some reproducible code:下面是一些可重现的代码:
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)
You seem to be trying to plot the ctree
object using base graphics but it is grid-based just like the plot from VennDiagram()
.您似乎正在尝试使用基本图形绘制ctree
对象,但它是基于网格的,就像来自VennDiagram()
的图一样。 Below is a working sample.下面是一个工作示例。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.