R:更改绘图大小 [英] R: Changing Plot Sizes

查看:42
本文介绍了R:更改绘图大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R编程语言.我使用"rpart"运行了决策树函数.库:

 库(rpart)z.auto<-rpart(里程〜重量,汽车测试框架) 

在这里,我试图绘制结果:

 图(z.auto) 

这将返回以下图:

以及一些警告消息:

 警告消息:1:在doTryCatch(return(expr),name,parentenv,handler)中:"use.n"不是图形参数2:在doTryCatch(return(expr),name,parentenv,handler)中:"use.n"不是图形参数3:在doTryCatch(return(expr),name,parentenv,handler)中:"use.n"不是图形参数4:在doTryCatch(return(expr),name,parentenv,handler)中:"use.n"不是图形参数5:在doTryCatch(return(expr),name,parentenv,handler)中:"use.n"不是图形参数6:在doTryCatch(return(expr),name,parentenv,handler)中:"use.n"不是图形参数7:在doTryCatch(return(expr),name,parentenv,handler)中:"use.n"不是图形参数8:在doTryCatch(return(expr),name,parentenv,handler)中:"use.n"不是图形参数9:在doTryCatch(return(expr),name,parentenv,handler)中:"use.n"不是图形参数 

我正在尝试在该图中添加更多信息(例如变量名称和决策规则).我进行了一些研究,发现可以在此图中添加标签:

  text(z.auto,use.n = TRUE) 

这将返回以下图:

此图更好-但是文本被切向底部.是否有一种简单的方法来更改绘图的内部大小,以使所有文本都显示出来而不会被截断?

注意:我使用的计算机没有Internet连接或USB端口-它只有R和一些常见的库(例如ggplot2,rpart,party,partykit等),我无法安装"rpart.plot"我的计算机上的库(

I am using the R programming language. I ran a decision tree function using the "rpart" library:

library(rpart)
z.auto <- rpart(Mileage ~ Weight, car.test.frame)

From here, I tried to plot the results:

 plot(z.auto)

This returns the following plot:

As well as several warning messages:

Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
2: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
3: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
4: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
5: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
6: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
7: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
8: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
9: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter

I am trying to add more information this plot (such as the variable names and the decision rules). I did some research and found out that you can add labels to this plot:

text(z.auto, use.n=TRUE)

This returns the following plot:

This plot is better - but the text is being cut off towards the bottom. Is there a straightforward way to change the internal size of the plot so that all the text appears without being cut off?

Note: I am using a computer that does not have an internet connection or a USB port - it just has R with some common libraries (e.g. ggplot2, rpart, party, partykit, etc.), I am NOT able to install the "rpart.plot" library on my computer (https://www.rdocumentation.org/packages/rpart.plot/versions/3.0.9), otherwise I would have tried to use this library instead.

Thank you

解决方案

Use xpd=TRUE. Also cex= might be helpful to scale font size.

plot(z.auto)
text(z.auto, use.n=TRUE, xpd=TRUE, cex=.8)

这篇关于R:更改绘图大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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