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.
You can use the following syntax to change the legend labels in ggplot2: p + scale_fill_discrete(labels=c('label1', 'label2', 'label3', ...))
You can place the legend literally anywhere. To put it around the chart, use the legend. position option and specify top , right , bottom , or left . To put it inside the plot area, specify a vector of length 2, both values going between 0 and 1 and giving the x and y coordinates.
Example 1: Remove All Legends in ggplot2 We simply had to specify legend. position = “none” within the theme options to get rid of both legends.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With