Re: [R] ggplot2: Choosing colours

From: ONKELINX, Thierry <Thierry.ONKELINX_at_inbo.be>
Date: Mon, 3 Dec 2007 15:51:55 +0100

Thanks Hadley.

The page you referred to was actually
http://had.co.nz/ggplot2/scale_identity.html

The solution to my problem was

library(ggplot2)
dataset <- data.frame(x = rnorm(40), y = runif(40), z = gl(4, 10, labels = LETTERS[1:4]))
dataset$MyColour <- factor(dataset$z, labels = c("red", "green", "blue", "black"))
ggplot(data = dataset, aes(x = x, y = y, colour = MyColour)) + geom_point() + scale_colour_identity(labels=levels(dataset$z), grob="tile", name="z")




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx_at_inbo.be
www.inbo.be

Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: hadley wickham [mailto:h.wickham_at_gmail.com] Verzonden: maandag 3 december 2007 15:23 Aan: ONKELINX, Thierry
CC: r-help_at_r-project.org
Onderwerp: Re: [R] ggplot2: Choosing colours

Hi Thierry,

Have a look at http://had.co.nz/ggplot2/scale_identity. (The way you are currently doing it only works because you are not using any kind of grouping/facetting, and I'm thinking about adding an explicit message/warning for this case)

Hadley

On 12/3/07, ONKELINX, Thierry <Thierry.ONKELINX_at_inbo.be> wrote:
> Dear useRs,
>
> I'm trying to specify the colour of a factor with ggplot2. The example
> below gets me close to what I want, but it's missing a legend.
>
> Any ideas?
>
> Thanks,
>
> Thierry
>
> library(ggplot2)
> dataset <- data.frame(x = rnorm(40), y = runif(40), z = gl(4, 10,
labels
> = LETTERS[1:4]))
> ggplot(data = dataset, aes(x = x, y = y, group = z)) +
geom_point(colour
> = c("red", "green", "blue", "black"))
>
>
>



> ----
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature
> and Forest
> Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
> methodology and quality assurance
> Gaverstraat 4
> 9500 Geraardsbergen
> Belgium
> tel. + 32 54/436 185
> Thierry.Onkelinx_at_inbo.be
> www.inbo.be
>
> Do not put your faith in what statistics say until you have carefully
> considered what they do not say. ~William W. Watt
> A statistical analysis, properly conducted, is a delicate dissection
of
> uncertainties, a surgery of suppositions. ~M.J.Moroney
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
-- 
http://had.co.nz/

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 03 Dec 2007 - 14:54:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 03 Dec 2007 - 15:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.