1
votes

I've been producing a number of nice plots with the plotLearnerPrediction function in the mlr package for R. They look like this. From looking into the source code of the plotLearnerPrediction function it looks like the color surfaces are made with geom_tile. A plot can for example be made by:

library(mlr)
data(iris)

#make a learner
lrn <- "classif.qda"
#make a task
my.task <- makeClassifTask(data = iris, target = "Species")
#make plot
plotLearnerPrediction(learner = lrn, task = my.task)

Now I wish to change the colors, using another red, blue and green tone to match those of some other plots that I've made for a project. for this I tried scale_fill_continuous and scale_fill_manual without any luck (Error: Discrete value supplied to continuous scale) I also wish to change the legend title and the labels for each legend entry (Which I tried giving appropriate parameters to the above scale_fill's). There's a lot of info out there on how to set the geom_tile colours when producing the plot, but I haven't found any info on how to do this post-production (i.e. in somebody else's plot object). Any help would be much appreciated.

1
plotLearnerPrediction returns the ggplot2 object, so you should be able to change those things. Can you post a complete example of what doesn't work please?Lars Kotthoff
It's not that I complain about stuff not working, I just don't know how to change the colors and other stuff as outlined above. If you run the code above, you get a plot that looks like the one in the link. Given you have such a plot how would you change the colors, legend title and legend labels?Greforb
You can modify some of these things through theme(), e.g. p = plotLearnerPrediction(...); p + theme(legend.position = "top"), but not everything can be customised this way. For some things you'll have to modify the source code.Lars Kotthoff

1 Answers

0
votes

When you look into the source code you see how the plot is generated and then you can see which scale has to be overwritten or set.

In this example it's fairly easy:

g = plotLearnerPrediction(learner = lrn, task = my.task)
library(ggplot2)
g + scale_fill_manual(values = c(setosa = "yellow", versicolor = "blue", virginica = "red"))

enter image description here