Discussion:
change legend order of ggplot in python
x***@gmail.com
2018-03-27 19:56:03 UTC
Permalink
I've met a problem of using ggplot in python.
<Loading Image...>
I have legends like this. How can I change the order of the legends to "0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19."?
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Brandon Hurr
2018-03-27 20:42:28 UTC
Permalink
When the numbers are converted to to factors they are made into characters
and sorted by that.

Easiest way is to make it a factor and supply the levels. Something like:

library(tidyverse)

my_data_frame %>%
mutate(label = factor(label, levels = 1:19) %>%
ggplot(., aes(x=x, y=y, colour = label) + geom_line()
Post by x***@gmail.com
I've met a problem of using ggplot in python.
<https://lh3.googleusercontent.com/-LnZ4kS2Y4yY/WrqbK52cHSI/AAAAAAAAAHI/M26Ge3hoWqwRFvj1F-JtoyQfq-Pv2JcPwCLcBGAs/s1600/Screen%2BShot%2B2018-03-27%2Bat%2B2.26.44%2BPM.png>
I have legends like this. How can I change the order of the legends to "0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19."?
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/
devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
x***@gmail.com
2018-03-27 21:10:50 UTC
Permalink
Is this for R or Python?

圚 2018幎3月27日星期二 UTC-5䞋午3:43:05Brandon Hurr写道
Post by Brandon Hurr
When the numbers are converted to to factors they are made into characters
and sorted by that.
library(tidyverse)
my_data_frame %>%
mutate(label = factor(label, levels = 1:19) %>%
ggplot(., aes(x=x, y=y, colour = label) + geom_line()
Post by x***@gmail.com
I've met a problem of using ggplot in python.
<https://lh3.googleusercontent.com/-LnZ4kS2Y4yY/WrqbK52cHSI/AAAAAAAAAHI/M26Ge3hoWqwRFvj1F-JtoyQfq-Pv2JcPwCLcBGAs/s1600/Screen%2BShot%2B2018-03-27%2Bat%2B2.26.44%2BPM.png>
I have legends like this. How can I change the order of the legends to
"0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19."?
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups
"ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Brandon Hurr
2018-03-27 21:24:49 UTC
Permalink
That is R code. If you have code to share that would be helpful because I
don’t knohave how you’re using ggplot within python.
Post by x***@gmail.com
Is this for R or Python?
圚 2018幎3月27日星期二 UTC-5䞋午3:43:05Brandon Hurr写道
Post by Brandon Hurr
When the numbers are converted to to factors they are made into
characters and sorted by that.
library(tidyverse)
my_data_frame %>%
mutate(label = factor(label, levels = 1:19) %>%
ggplot(., aes(x=x, y=y, colour = label) + geom_line()
I've met a problem of using ggplot in python.
Post by Brandon Hurr
Post by x***@gmail.com
<https://lh3.googleusercontent.com/-LnZ4kS2Y4yY/WrqbK52cHSI/AAAAAAAAAHI/M26Ge3hoWqwRFvj1F-JtoyQfq-Pv2JcPwCLcBGAs/s1600/Screen%2BShot%2B2018-03-27%2Bat%2B2.26.44%2BPM.png>
I have legends like this. How can I change the order of the legends to
"0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19."?
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google
Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an
Post by x***@gmail.com
For more options, visit https://groups.google.com/d/optout.
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...