[R] Use of colour in plots

Steve Murray smurray444 at hotmail.com
Fri Sep 19 16:01:05 CEST 2008


Sorry - I should've maybe also pointed out that the command I've been trying to use is: alpha(col="green", 1/10)

On its own this results in the following error: [1] "#00FF001A"  and I haven't been able to successfully incorporate it into the main formula just yet (please see my previous message).

Without wanting to get too far ahead of myself, is there also a way of making the red points transparent too? (within this command - I've tried using '&' but this results in an error).

Many thanks again for any advice you can offer,

Steve



> From: smurray444 at hotmail.com
> To: thierry.onkelinx at inbo.be; r-help at r-project.org
> Subject: RE: [R] Use of colour in plots
> Date: Fri, 19 Sep 2008 13:45:43 +0000
>
>
> Thierry,
>
> Thanks - I've had a look into using the transparency option, but can't seem to work out where to place it within the command I'm using:
>
>> ggplot(Jan, aes(x = PopDensity, y = Average.Burnt.Area.Fraction, colour = factor(Urban.Rural> 1.25))) + geom_point()
>
> I'm assuming that it has to go in the 'aes' section somewhere, but I seem to be encountering errors wherever I insert it. This doesn't seem to be mentioned in the book, so do you have any tips?!
>
> Also, out of interest, what does the 'geom_point()' command do?
>
> Thanks again,
>
> Steve
>
>
>
>> Subject: RE: [R] Use of colour in plots
>> Date: Fri, 19 Sep 2008 10:31:58 +0200
>> From: Thierry.ONKELINX at inbo.be
>> To: smurray444 at hotmail.com; r-help at r-project.org
>>
>> Steve,
>>
>> - Use tranparancy to prevent overplotting: more details on p. 16 of the
>> ggplot2 book: http://had.co.nz/ggplot2/book/
>> - You can choose your own colour with scale_manual():
>> http://had.co.nz/ggplot2/scale_manual.html
>> - The backgroundcolor can be set with ggopt(background.color = "white"):
>> http://rweb.stat.umn.edu/R/library/ggplot/html/build-options-8a.html
>>
>> HTH,
>>
>> Thierry
>>
>>
>> ------------------------------------------------------------------------
>> ----
>> 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
>>
>> 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: Steve Murray [mailto:smurray444 at hotmail.com]
>> Verzonden: donderdag 18 september 2008 19:08
>> Aan: r-help at r-project.org; ONKELINX, Thierry; petr.pikal at precheza.cz;
>> jrkrideau at yahoo.ca; jim at bitwrit.com.au
>> Onderwerp: RE: [R] Use of colour in plots
>>
>>
>> Dear Thierry and all,
>>
>> I've tried out ggplot from the ggplot2 package and it seems to provide
>> much more favourable results!
>>
>> Just a few questions I have after consulting the 'help' file for ggplot.
>>
>> Is there a way of preventing overplotting? Some of the red points are
>> being obscured by the green ones. I've tried changing the size of the
>> points (using size=1) but this doesn't resolve the issue, as there are
>> many points quite densely packed in some parts of the graph.
>>
>> Also how would I change the colours if I wished (for future plots of a
>> similar format)? And how do you customise the legend?
>>
>> Finally, is there a way of changing the grey background of the graph to
>> white?
>>
>> Sorry for all the questions, it's just that I'm new to the ggplot2
>> package and can't find the answers in the help file or on the associated
>> website!
>>
>> Many thanks to anyone who's able to offer any advice.
>>
>> Best wishes,
>>
>> Steve
>>
>>
>>
>>> Subject: RE: [R] Use of colour in plots
>>> Date: Thu, 18 Sep 2008 14:52:57 +0200
>>> From: Thierry.ONKELINX at inbo.be
>>> To: smurray444 at hotmail.com; petr.pikal at precheza.cz; jrkrideau at yahoo.ca
>>> CC: r-help at r-project.org
>>>
>>> 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 at 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 at r-project.org
>> [mailto:r-help-bounces at r-project.org]
>>> Namens Steve Murray
>>> Verzonden: donderdag 18 september 2008 13:58
>>> Aan: Petr PIKAL; jrkrideau at yahoo.ca
>>> CC: r-help at 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 at yahoo.ca
>>>> CC: r-help at r-project.org; smurray444 at hotmail.com
>>>> Subject: Re: [R] Use of colour in plots
>>>> From: petr.pikal at precheza.cz
>>>> Date: Fri, 5 Sep 2008 16:40:47 +0200
>>>>
>>>> Hi
>>>>
>>>> r-help-bounces at 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 at 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 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.
>>>>>
>>>>> ______________________________________________
>>>>> 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.
>>>>
>>>
>>> ______________________________________________
>>> 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.
>>>
>>> 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.
>>
>> _________________________________________________________________
>> Discover Bird's Eye View now with Multimap from Live Search
>> http://clk.atdmt.com/UKM/go/111354026/direct/01/
>>
>> 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.
>
> _________________________________________________________________
> Win New York holidays with Kellogg’s & Live Search
> http://clk.atdmt.com/UKM/go/111354033/direct/01/



More information about the R-help mailing list