Anna Berthinussen
2010-Jul-29 17:51 UTC
[R] Colour points in plot according to third variable
Hi, I am using the plot function to make a simple plot of my data with one variable against another and want to colour the data points according to a third variable. The third variable is continuous (Time) and I want to try two different ways of colouring the data points, either: Divide time it into three groups and then colour each data point accordingly eg. 30-60 minutes in green, 60-90 minutes in red and 90-120 minutes in blue.. or, Colour the data points using a colour gradient eg. with increasing colour intensity as time increases.. I think I need to be able to do it within the plot() function as I have lines fitted from a model which I will also add to the graph. Any suggestions would be greatly appreciated?? Thanks in advance Anna
Henrique Dallazuanna
2010-Jul-29 17:56 UTC
[R] Colour points in plot according to third variable
Try this:
library(RColorBrewer)
plot(iris$Sepal.Length,
col = as.character(cut(iris$Sepal.Length, c(4,6,7,8), labels brewer.pal(3,
'Blues'))))
On Thu, Jul 29, 2010 at 2:51 PM, Anna Berthinussen
<bs06ab@leeds.ac.uk>wrote:
> Hi,
>
> I am using the plot function to make a simple plot of my data with one
> variable against another and want to colour the data points according to a
> third variable. The third variable is continuous (Time) and I want to try
> two different ways of colouring the data points, either:
>
> Divide time it into three groups and then colour each data point
> accordingly eg. 30-60 minutes in green, 60-90 minutes in red and 90-120
> minutes in blue..
>
> or,
>
> Colour the data points using a colour gradient eg. with increasing colour
> intensity as time increases..
>
> I think I need to be able to do it within the plot() function as I have
> lines fitted from a model which I will also add to the graph.
>
> Any suggestions would be greatly appreciated??
>
> Thanks in advance
>
> Anna
>
> ______________________________________________
> R-help@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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]