有什么方法可以操纵ctree图的标题? [英] Is there any way to manipulate the titles of a ctree plot?

查看:96
本文介绍了有什么方法可以操纵ctree图的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改ctree图的标题大小?

Is there any way to change the title sizes of a ctree plot?

使用以下变量快速设置ctree图

Use the following variables to quickly set up a ctree plot

a<-c(41, 45, 50, 50, 38, 42, 50, 43, 37, 22, 42, 48, 47, 48, 50, 47, 41, 50, 45, 45, 39, 45, 46, 48, 50, 47, 50, 21, 48, 50, 48, 48, 48, 46, 36, 38, 50, 39, 44, 44, 50, 49, 40, 48, 48, 45, 39, 40, 44, 39, 40, 44, 42, 39, 49, 50, 50, 48, 48, 47, 48, 47, 44, 41, 50, 47, 50, 41, 50, 44, 47, 50, 24, 40, 43, 37, 44, 32, 43, 42, 44, 38, 42, 45, 50, 47, 46, 43,
37, 47, 37, 45, 41, 50, 42, 32, 43, 48, 45, 45, 28, 44,38, 41, 45, 48, 48, 47 ,49, 16, 45, 50, 47, 50, 43, 49, 50)

X1<-c(NA,NA,NA,NA,NA,1,2,2,2,NA,2,2,2,2,2,2,2,NA,NA,2,2,2,2,NA,2,2,2,2,2,2,2,NA,NA,NA,NA,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,NA,2,2,2,2,2,2,2,2,2,2,NA,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,1,2,2,2,2,2,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,2,2,1,2,2,2)
X2<-c(NA,NA,NA,NA,NA,NA,2,2,2,NA,NA,2,2,2,2,2,2,NA,2,2,2,2,2,NA,2,2,2,2,2,2,2,NA,NA,NA,NA,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,NA,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,1,2,2,2,2,2,2,2)
X3<-c(NA,35,40,NA,10,NA,31,NA,14,NA,NA,15,17,NA,NA,16,10,15,14,39,17,35,14,14,22,10,15,0,34,23,13,35,32,2,14,10,14,10,10,10,40,10,13,13,10,10,10,13,13,25,10,35,NA,13,NA,10,40,0,0,20,40,10,14,40,10,10,10,10,13,10,8,NA,NA,14,NA,10,28,10,10,15,15,16,10,10,35,16,NA,NA,NA,NA,30,19,14,30,10,10,8,10,21,10,10,35,15,34,10,39,NA,10,10,6,16,10,10,10,10,34,10)
X4<-c(NA,NA,511,NA,NA,NA,NA,NA,849,NA,NA,NA,NA,1324,1181,832,1005,166,204,1253,529,317,294,NA,514,801,534,1319,272,315,572,96,666,236,842,980,290,843,904,528,27,366,540,560,659,107,63,20,1184,1052,214,46,139,310,872,891,651,687,434,1115,1289,455,764,938,1188,105,757,719,1236,982,710,NA,NA,632,NA,546,747,941,1257,99,133,61,249,NA,NA,1080,NA,645,19,107,486,1198,276,777,738,1073,539,1096,686,505,104,5,55,553,1023,1333,NA,NA,969,691,1227,1059,358,991,1019,NA,1216)

p<-cbind(X1,X2,X3,X4)

接下来,您应该得到下面的图

With the following you should then get the plot below

library(party)  
urp<-ctree(a~., data=data.frame(a,p))
plot(urp, main = "Broken Title")

如何更改标题大小?我已经尝试了以下无用的方法:

How do I change the title size? I've tried the following which does nothing:

plot(urp, main = "Broken Title",cex = 1.5)
plot(urp, main = "Broken Title",cex.main = 1.5)

实际上,我可以操纵标题吗? font.main同样不执行任何操作.标题为节点2"和节点3"的标题如何?同样没有办法让我操纵它们吗?

In fact, can I manipulate the title at all? font.main similarly does nothing. What about the titles "Node 2" and "Node 3." Is there likewise no way for me to manipulate them?

在这里提出了类似的问题: > https://stackoverflow.com/questions/18817522/ctree-changing-titles-of-内部节点

A similar question was asked here: https://stackoverflow.com/questions/18817522/ctree-changing-titles-of-inner-nodes

推荐答案

好消息和坏消息.

因此实际上执行所有工作的plot()函数是party:::plot.BinaryTree.可从?plot.BinaryTree获得该帮助,但坏消息是它没有用于字体格式设置的任何易于访问的参数.但是,好消息是该函数使用网格图形绘制到屏幕上,并且可以在创建绘图后更新属性.

So the plot() function that's actually doing all the work there is party:::plot.BinaryTree. The help is available from ?plot.BinaryTree but the bad news is it doesn't have any easily accessible parameters for font formatting. However, the good news is that the function uses grid graphics to draw to the screen and you can update properties after you've created the plot.

所以在运行之后

library(party)  
urp<-ctree(a~., data=data.frame(a,p))
plot(urp, main = "Broken Title")

您可以运行

for(gg in grid.ls(print=F)[[1]]) {
   if (grepl("text", gg)) {
       print(paste(gg, grid.get(gg)$label,sep=": "))
   }
}

以查看绘图上的所有文本框.例如,我看到

to see all the text boxes on the plot. For example, I see

[1] "GRID.text.673: Broken Title"
[1] "GRID.text.677: X1"
[1] "GRID.text.678: p = 0.03"
[1] "GRID.text.680: 1"
[1] "GRID.text.682: phantom(0) <= 1"
[1] "GRID.text.684: phantom(0) > 1"
[1] "GRID.text.686: Node 2 (n = 8)"
[1] "GRID.text.697: Node 3 (n = 109)"

在这里,我看到节点名称及其包含的文本.请注意,每个图的节点名称都不相同,并且更改绘制相同图的所有内容.但是您可以使用此列表找到要更改和更新的列表.因此,如果我想使主要文本变大,我会运行

Here i see the node names, and the text they contain. Note that the node names are not the same from plot to plot and change everything you draw the same plot. But you can use this list to find the ones you want to change and update them. So if I wanted to make the main text bigger, I would run

grid.edit("GRID.text.673", gp=gpar(fontsize=20))

或者如果我想使节点标签变成斜体,我将运行

or If i wanted to italize the node labels i would run

grid.edit("GRID.text.686", gp=gpar(fontface=3))
grid.edit("GRID.text.697", gp=gpar(fontface=3))

然后给出

这篇关于有什么方法可以操纵ctree图的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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