R ggplot2:图例应该是离散的而不是连续的 [英] R ggplot2: legend should be discrete and not continuous

查看:208
本文介绍了R ggplot2:图例应该是离散的而不是连续的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据:

benchmark   mispredpenal    IPC     pred
ammp        1               1.0589  2lev
ammp        5               1.0450  2lev
...

并使用以下命令:

ggplot(IPC, aes(x = benchmark, y = IPC, group=mispredpenal, colour=mispredpenal)) + 
  geom_point() + geom_line()

一切看起来都应该如此,但是我希望图例是离散的,而不是连续的(渐变的).我该怎么办?

Everything looks like it should, but I would like the legend to be discrete, and not the continuous (gradient). How should I do this?

修改: 错误错误是1、5、9、13或17.

Misprediction is either 1, 5, 9, 13 or 17.

推荐答案

在这种情况下,您希望变量mispredpenalfactor:

You want the variable mispredpenal to be a factor in that case:

ggplot(IPC, aes(x = benchmark, y = IPC, group=factor(mispredpenal), colour=factor(mispredpenal))) + 
  geom_point() + geom_line()

这篇关于R ggplot2:图例应该是离散的而不是连续的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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