更改plotLearnerPrediction ggplot2对象的颜色和图例 [英] Change color and legend of plotLearnerPrediction ggplot2 object

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

问题描述

我已经使用R的mlr包中的plotLearnerPrediction函数制作了许多漂亮的图.它们看起来像.通过查看plotLearnerPrediction函数的源代码,看起来好像彩色表面是用geom_tile制作的. 例如,可以通过以下方式制作图:

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)

现在,我希望更改颜色,使用另一种红色,蓝色和绿色来匹配我为项目制作的其他部分的颜色.为此,我尝试了scale_fill_continuousscale_fill_manual时没有任何运气(错误:离散值提供给连续刻度),我也希望更改图例标题和每个图例条目的标签(我尝试为上述scale_fill的).有很多关于如何在制作绘图时设置geom_tile颜色的信息,但是我还没有找到有关如何进行后期制作(即在其他人的绘图对象中)的任何信息.任何帮助将不胜感激.

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.

推荐答案

当您查看

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"))

这篇关于更改plotLearnerPrediction ggplot2对象的颜色和图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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