简体   繁体   English

R ggplot2:图例应该是离散的而不是连续的

[英]R ggplot2: legend should be discrete and not continuous

I have the following data:我有以下数据:

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

and use the following command:并使用以下命令:

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?我该怎么做?

Edit: Misprediction is either 1, 5, 9, 13 or 17.编辑:错误预测是 1、5、9、13 或 17。

You want the variable mispredpenal to be a factor in that case:在这种情况下,您希望变量mispredpenal成为一个factor

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM