0

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

enter image description here

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)
hhh
  • 50,788
  • 62
  • 179
  • 282
  • I assume you mean the `multiplot` function defined [here](http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/). The code you've posted works fine for me. Have you tried the github version of `mlr`? – Lars Kotthoff Jul 17 '17 at 22:50
  • @LarsKotthoff devtools::install_github("mlr-org/mlr") fires me many errors shown [here](https://pastebin.com/ykR8rMC6). – hhh Jul 17 '17 at 23:09
  • 1
    It's the `smote` package that these errors are coming from. You could install the binary version of that or upgrade your GCC. – Lars Kotthoff Jul 17 '17 at 23:15
  • @LarsKotthoff I compiled gcc without multilib, as shown [here](https://stackoverflow.com/a/45134672/164148), just yesterday because I wanted to get rJava compiled. How to install the binary version? As for Q, I am able to get the multiplot working without RStudio so somehow RStudio is messing things up, it crashes the multiplot. – hhh Jul 17 '17 at 23:18
  • 1
    Ok, so it's an RStudio issue. Glad that it's working for you with the CRAN mlr version. – Lars Kotthoff Jul 17 '17 at 23:36
  • @LarsKotthoff yes, does this smote refer to smote of WEKA [here](http://weka.sourceforge.net/doc.packages/SMOTE/weka/filters/supervised/instance/SMOTE.html) or something else in the case of MLR? Perhaps, the github MLR is already using different version of RWeka? Still, I cannot undersand why things fail in RStudio but not inside my termial: actually I have R-app compiled from brew on terminal while RStudio may use some different R setup. – hhh Jul 17 '17 at 23:42
  • 1
    No, the smote actually comes with mlr -- my bad. I don't use RStudio, so I'm afraid I can't help you with that. – Lars Kotthoff Jul 17 '17 at 23:44
  • @LarsKotthoff just curious, have you found some better IDE or editor setup for R development? – hhh Jul 17 '17 at 23:47
  • I use vim. Works well for me. – Lars Kotthoff Jul 17 '17 at 23:48
  • @LarsKotthoff me too but are you using some special setup? – hhh Jul 17 '17 at 23:49
  • Not really. I'm not using anything specifically for R. – Lars Kotthoff Jul 17 '17 at 23:54

1 Answers1

0

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)
Ruben Kazumov
  • 3,803
  • 2
  • 26
  • 39