[R] Use of colour in plots

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Thu Sep 18 14:52:57 CEST 2008


Steve,

Have a look at the ggplot2 package: 

library(ggplot2)
ggplot(Jan, aes(x = PopDensity, y = Average.Burnt.Area.Fraction, colour
= factor(Urban.Rural > 1.25))) + geom_point()


------------------------------------------------------------------------
----
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 op inbo.be 
www.inbo.be 

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Steve Murray
Verzonden: donderdag 18 september 2008 13:58
Aan: Petr PIKAL; jrkrideau op yahoo.ca
CC: r-help op r-project.org
Onderwerp: Re: [R] Use of colour in plots


Dear all,

I've finally got round to plotting my data and trying to apply colour
(had some problems with the data which I needed to rectify first!). I'm
having trouble however getting the colour to work as I'd hoped, despite
the help offered in previous messages.

Just to recap, and with more specifics this time, I have a data frame as
follows:


> head(Jan)
  Latitude Longitude Urban.Rural Average.Burnt.Area.Fraction PopDensity
GDP
1    -0.25    -49.25    1.000000                       9e-05  1.8703090
25694
2    -0.25    -50.25    1.000000                       2e-05  2.5962470
32205
3    -0.25    -50.75    1.000000                       0e+00  3.5221470
39312
4    -0.25    -51.25    1.042432                       5e-06 14.2919000
87685
5    -0.25    -51.75    1.000000                       1e-05  0.5721315
11376
6    -0.25    -52.25    1.000000                       4e-05  0.7262031
11083
  Cropland.Area..km.2.grid.cell.
1                      0.4260444
2                      0.3401146
3                      0.3036076
4                      0.3147694
5                      0.2843388
6                      0.1734099


I hope to plot Average.Burnt.Area.Fraction (ABAF) against PopDensity
(which I have done using:> plot(Jan[,3],Jan[,4]) ).

However, the twist is, I hope these points to be coloured according to
the values of Urban.Rural (but don't want this column to actually be
plotted). I am looking to do, if Urban.Rural>1.25 then colour the point
red, and if it's = To: jrkrideau op yahoo.ca
> CC: r-help op r-project.org; smurray444 op hotmail.com
> Subject: Re: [R] Use of colour in plots
> From: petr.pikal op precheza.cz
> Date: Fri, 5 Sep 2008 16:40:47 +0200
>
> Hi
>
> r-help-bounces op r-project.org napsal dne 05.09.2008 16:24:35:
>
>> Here is an example doing the same type of thing.
>> It should be easy enough to adapt.
>>
>> Good luck
>>
>> ===========================================================
>> x <- runif(100, 0, 1)
>> y <- runif(100, 0, 1)
>> z <- data.frame(x,y)
>>
>> plot(subset(z, z$y>=.5), col="red", ylim=c(min(z$y),
>> max(z$y)), pch=16)
>> points(subset(z, z$y <=.49), col="blue", pch=16)
>> ===========================================================
>
> Or
>
> third <- (z$y>=.5)+1
> plot(z, col=third, pch=16)
>
> Just tell to col a vector of colors with appropriate use of logical.
>
> Or you can use col = as.numeric(some factor), which is quite
convenient
> use of factors feature which is not desired in other cases.
> See warning section of factor help page.
>
> Regards
>
>>
>>
>> --- On Fri, 9/5/08, Steve Murray  wrote:
>>
>>> From: Steve Murray 
>>> Subject: [R] Use of colour in plots
>>> To: r-help op r-project.org
>>> Received: Friday, September 5, 2008, 9:10 AM
>>> Dear all,
>>>
>>> I have 3 datasets all of which share the same longitude and
>>> latitude values, which I'm looking to plot onto a
>>> scattergraph. The third dataset has values which can only be
>>> either '1' or '2'. So to incorporate all
>>> three datasets onto two axes, I'm wondering if I can
>>> plot dataset1 and dataset2 as normal, but then use colour to
>>> determine whether these points are either values '1'
>>> or '2' according to the third dataset.
>>>
>>> If so, how would I go about doing this in R, and what
>>> format would the command take?
>>>
>>> Thanks for any help offered,
>>>
>>> Steve
>>>
>>> ______________________________________________
>>> R-help op 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.
>>
>> ______________________________________________
>> R-help op 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.
>

______________________________________________
R-help op 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.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in  this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.



More information about the R-help mailing list