[R] Use of colour in plots
smurray444 at hotmail.com
Thu Sep 18 13:58:12 CEST 2008
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:
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
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
> 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)
> 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.
>> --- 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,
>>> R-help at r-project.org mailing list
>>> PLEASE do read the posting guide
>>> and provide commented, minimal, self-contained,
>>> reproducible code.
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help