2015-05-21 85 views
1

我试图通过下面的代码找到一种方法来保存为pdf后在fancyRpartPlot后面出现的图像输出来绘制回归树。 任何人都知道我该怎么做?我无法通过网络找到任何答案。保存一个fancyRpartPlot为pdf

regression_tree <- data.frame(stock_mag = as.numeric(resData$stock_mag), 
        LT = as.numeric(resData$Lead_Time), 
        dmIn = as.numeric(resData$Intermittency), 
        dmCv = as.numeric(resData$CoV)) 

fit<-rpart(stock_mag~dmCv+dmIn+LT,data=regression_tree, method="anova",   control=rpart.control(minsplit=20)) 
x11() 

fancyRpartPlot(fit, main="test") # Will plot the tree# 

谢谢!!

+0

欢迎SO!请习惯于提供像这里描述的可重现的例子:http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – lukeA

回答

0

这应该工作一样使用pdf()所有其他情节:

library(rattle) 
library(rpart) 
set.seed(42) 
ds  <- weather 
target <- "RainTomorrow" 
risk <- "RISK_MM" 
ignore <- c("Date", "Location", risk) 
vars <- setdiff(names(ds), ignore) 
nobs <- nrow(ds) 
form <- formula(paste(target, "~ .")) 
train <- sample(nobs, 0.7*nobs) 
test <- setdiff(seq_len(nobs), train) 
actual <- ds[test, target] 
risks <- ds[test, risk] 
model <- rpart(form, data=ds[train, vars]) 

pdf(tf <- tempfile(fileext = ".pdf")) 
fancyRpartPlot(model) 
dev.off() 
cat(tf) # filename 
+0

我试着你说的,但当我试图打开它在Windows(我在Windows环境中使用R工作室)它没有找到程序来打开它。也许我必须指定一些参数或什么? – Aida

+0

你的意思是没有与pdf扩展相关的程序?那么这将是一个Windows问题。 – lukeA

+0

解决了,土坯没有正确安装在窗户我修好了,现在它的工作。谢谢! – Aida