R:RStudio中MLR触发错误的plotLearnerPrediction ggplot对象的多重绘图 [英] R: multiplot for plotLearnerPrediction ggplot objects of MLR firing errors in RStudio

查看:78
本文介绍了R:RStudio中MLR触发错误的plotLearnerPrediction ggplot对象的多重绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本文

如此

如何在RStudio的同一张图片中并排绘制许多plotLearnerPrediction对象?

 库(mlr)#此处的多个绘图功能在RStudio中以p1,p2,p3,...失败#但是我可以在没有RStudio的情况下运行此程序.#http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/学习者=列表(makeLearner("classif.svm",内核=线性"),makeLearner("classif.svm",内核=多项式"),makeLearner("classif.svm",kernel ="radial"),"classif.qda","classif.randomForest","classif.knn")p1< -plotLearnerPrediction(学习者=学习者[[1]],任务= iris.task)p2< -plotLearnerPrediction(学习者=学习者[[2]],任务= iris.task)p3< -plotLearnerPrediction(学习者=学习者[[3]],任务= iris.task)p4< -plotLearnerPrediction(学习者=学习者[[4]],任务= iris.task)#p5< -plotLearnerPrediction(学习者=学习者[[5]],任务= iris.task)#p6< -plotLearnerPrediction(学习者=学习者[[6]],任务= iris.task)#multiplot(p1,p2,p3,p4,p5,p6,cols = 2)#在Rstudio中失败#multiplot(p1,p2,p3,p4,cols = 1)#在Rstudio中失败但并非没有 

RStudio版本

 >版本_平台x86_64-apple-darwin15.6.0拱x86_64操作系统darwin15.6.0系统x86_64,darwin15.6.0地位大三次要4.1一年201706个月30天svn版本72865语言Rversion.string R版本3.4.1(2017-06-30)昵称Single Candle 

命令行上的

R

  $ R-版本R版本3.4.1(2017-06-30)-单蜡烛"版权所有(C)2017 The R Foundation for Statistical Computing平台:x86_64-apple-darwin15.6.0(64位) 

解决方案

您可以使用库 gridExtra :

  require(gridExtra)图书馆(gridExtra)p1<-plotLearnerPrediction(学习者=学习者[[1]],任务= iris.task)...p4<-plotLearnerPrediction(学习者=学习者[[4]],任务= iris.task)grid.arrange(p1,p2,p3,p4,ncol = 2,现在= 2) 

The article here demonstrates the MLR package. The plotLearnerPrediction function returns an ggplot object by this. I tried the multiplot function provided for ggplot2 objects below but my RStudio crashes with it. I am able to plot things without RStudio

so

How can I plot many plotLearnerPrediction objects in the same picture side-by-side in RStudio?

library(mlr)

# Multiple plot function here failing with p1,p2,p3,... in RStudio
# but I am able to run this thing without RStudio.
# http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/

learners = list( makeLearner("classif.svm", kernel = "linear"), 
                 makeLearner("classif.svm", kernel = "polynomial"), 
                 makeLearner("classif.svm", kernel = "radial"), 
                 "classif.qda", 
                 "classif.randomForest", 
                 "classif.knn" )

p1<-plotLearnerPrediction(learner = learners[[1]], task = iris.task)
p2<-plotLearnerPrediction(learner = learners[[2]], task = iris.task)
p3<-plotLearnerPrediction(learner = learners[[3]], task = iris.task)
p4<-plotLearnerPrediction(learner = learners[[4]], task = iris.task)
#p5<-plotLearnerPrediction(learner = learners[[5]], task = iris.task)
#p6<-plotLearnerPrediction(learner = learners[[6]], task = iris.task)

#multiplot(p1, p2, p3, p4, p5, p6, cols=2) #failing in Rstudio
#multiplot(p1, p2, p3, p4, cols=1) #failing in Rstudio but not without it

RStudio version

> version
               _                           
platform       x86_64-apple-darwin15.6.0   
arch           x86_64                      
os             darwin15.6.0                
system         x86_64, darwin15.6.0        
status                                     
major          3                           
minor          4.1                         
year           2017                        
month          06                          
day            30                          
svn rev        72865                       
language       R                           
version.string R version 3.4.1 (2017-06-30)
nickname       Single Candle               

R on the command line

$ R --version
R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

解决方案

You can use library gridExtra:

    require(gridExtra)
    library(gridExtra)
    p1 <- plotLearnerPrediction(learner = learners[[1]], task = iris.task)
    ...
    p4 <- plotLearnerPrediction(learner = learners[[4]], task = iris.task)
    grid.arrange(p1, p2, p3, p4, ncol = 2, now = 2)

这篇关于R:RStudio中MLR触发错误的plotLearnerPrediction ggplot对象的多重绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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