The ggplot2 manual at http://had.co.nz/ggplot2/scale_manual.html suggests using a structure like:
values = c("8" = "red","4" = "blue","6" = "darkgreen", "10" = "orange")
to assign specific colours to values.
How does one generate this structure from two arrays:
A = c("8","4","6","10"); B = c("red","blue","darkgreen","orange")
I got as far as:
rbind(A,B)
[,1] [,2] [,3] [,4]
A "8" "4" "6" "10"
B "red" "blue" "darkgreen" "orange"
But I am not sure how to turn that into an array of "X" = "Y" assignments.
names(B) <- A
But in this particular case I would rather use
scale_colour_manual(breaks=A, values=B)
Jean-Olivier Irisson
---
Observatoire Océanologique
Station Zoologique, B.P. 28, Chemin du Lazaret
06230 Villefranche-sur-Mer
Tel: +33 04 93 76 38 04
Mob: +33 06 21 05 19 90
http://jo.irisson.com/
> How does one generate this structure from two arrays:names(B) <- A
>
> A = c("8","4","6","10"); B = c("red","blue","darkgreen","orange")
But in this particular case I would rather use
scale_colour_manual(breaks=A, values=B)
If you keep the same order in the breaks and the colours, it should give you what you want, i.e.
scale_colour_manual(breaks=c(1,2,3), values=c("red", "green", "blue"))
scale_colour_manual(breaks=c(3,2,1), values=c("blue" , "green","red"))
scale_colour_manual(breaks=c(1,3,2), values=c("red", "blue", "green"))
give the same graphic, only the legend key is changed.
Ooops no it does not. Sorry, the only way to do it is with a named vector indeed.
That's strange tough, it would seem natural to do it this way. Hadley?
setNames(A, B)
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
Well, a lot of things seems natural, but it's not always possible. I
think there was also a bug that's been fixed in the devel version that
may be relevant.
--
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 ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
That's very strange. What are breaks for then?
Controlling the legend (the display, not the underlying mapping).