BinaryTree(树,聚会)的图忽略par()的图选项 [英] Plot of BinaryTree (ctree, party) ignores plot option of par()

查看:74
本文介绍了BinaryTree(树,聚会)的图忽略par()的图选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图的较高部分绘制BinaryTree,并在第二部分(底部)绘制第二个树.这是一些示例代码,表明树的图完全忽略了par()

I would like to plot the BinaryTree in the uppper part of the plot, and make a second one in the second part (bottom). Here is some example code to show, that the plot of the tree completely ignores the partitioning options set by par()

library("party")
### regression
airct <- ctree(Ozone ~ ., data = subset(airquality, !is.na(Ozone)))
### classification
irisct <- ctree(Species ~ .,data = iris)

par(mfrow = c(2, 1))
plot(airct)
plot(irisct)

此代码不会在同一图(页)中绘制两棵树.我该如何纠正?

This code does not plot the two trees in the same plot (page). How can I correct this?

即使遵循非常详细的答案在这种情况下也不起作用: ctree的绘制将忽略所有已建立的选项.

Even when following the very detailed answer does not work in this case: plots generated by 'plot' and 'ggplot' side-by-side the plotting of a ctree ignores all established options.

推荐答案

party中的图及其后继程序包partykit是在grid中实现的,因此par()中的base图形选项例如mfrow不起作用.除了注释中的注释之外,您还可以使用grid.layout()获得类似的结果.

The plots in party and its successor package partykit are implemented in grid and hence the base graphics options from par() such as mfrow do not work. In addition to the remarks from the comments, you can use grid.layout() to achieve similar results.

在纯网格中这样做有点技术性,但是代码应该不会太难遵循:

Doing so in plain grid is a bit technical but the code should not be too hard to follow:

grid.newpage()
pushViewport(viewport(layout = grid.layout(2, 1)))

pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 1))
plot(airct, newpage = FALSE)
popViewport()

pushViewport(viewport(layout.pos.row = 2, layout.pos.col = 1))
plot(irisct, newpage = FALSE)
popViewport()

使用newpage = FALSE参数的原因是,默认情况下,绘图是在新页面上绘制的,而不是添加到可能存在的绘图中.

The reason for the newpage = FALSE argument is that by default the plot is drawn on a new page, rather than adding to a potentially existing plot.

这篇关于BinaryTree(树,聚会)的图忽略par()的图选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆