Hi all
Does anyone know if it is possible when plotting a line or scatter plot, to
selectively color the data points based on the data value? i.e. if plotting say
the percentage change in stock price movements, to color +ve points in green and
-ve points in red? And extending this to a user-defined range of colors based on
the quartile of the data points?
Thanks
Rory
Rory Winston
RBS Global Banking & Markets
280 Bishopsgate, London, EC2M 4RB
Office: +44 20 7085 4476
***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered
Office: 36 St Andrew Square, Edinburgh EH2 2YB.
Authorised and regulated by the Financial Services Authority
This e-mail message is confidential and for use by the=2...{{dropped:25}}
Try this: tmp <- with(iris, seq( min(Petal.Length)-1, max(Petal.Length)+1, length.out=6)) with( iris, plot( Sepal.Width, Sepal.Length, col=topo.colors(5)[ cut(Petal.Length,tmp) ] ) ) hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Rory.WINSTON at rbs.com > Sent: Tuesday, November 25, 2008 10:35 AM > To: r-help at r-project.org > Subject: [R] Line color based on data values? > > Hi all > > Does anyone know if it is possible when plotting a line or scatter > plot, to selectively color the data points based on the data value? > i.e. if plotting say the percentage change in stock price movements, to > color +ve points in green and -ve points in red? And extending this to > a user-defined range of colors based on the quartile of the data > points? > > Thanks > Rory > > Rory Winston > RBS Global Banking & Markets > 280 Bishopsgate, London, EC2M 4RB > Office: +44 20 7085 4476 > > > > *********************************************************************** > ************ > The Royal Bank of Scotland plc. Registered in Scotland No 90312. > Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB. > Authorised and regulated by the Financial Services Authority > > This e-mail message is confidential and for use by > the=2...{{dropped:25}} > > ______________________________________________ > 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.
Hi,
for example:
today=rnorm(100)
yesterday=rnorm(100)
up=today[today>yesterday]
down=today[today<yesterday]
index.up=which(today>yesterday)
index.down=which(today<yesterday)
plot(up~yesterday[index.up],col="green",xlim=c(-5,5),ylim=c(-5,5))
points(down~yesterday[index.down],col="red")
today: today's returns
yesterday: yesterday's return
up: returns if returns today are greater than yesterday
down: return if returns are smaller than yesterday
(for pairs of observations)
index.up: index number of observations for which up==true
index.down: index number of obersvations for which down=true
plot: first plot today's returns against yesterday's returns
for stocks that are up only (adjust plotting limits of x and y axis so as
to accomodate the later plot of down stocks; plot ups in green)
points: plot today's return against yesterday's returns for stocks that
are
down only (plot in the same plot generated above; plot in red)
Cheers,
Daniel
-------------------------
cuncta stricte discussurus
-------------------------
-----Urspr?ngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Rory.WINSTON at rbs.com
Gesendet: Tuesday, November 25, 2008 12:35 PM
An: r-help at r-project.org
Betreff: [R] Line color based on data values?
Hi all
Does anyone know if it is possible when plotting a line or scatter plot, to
selectively color the data points based on the data value? i.e. if plotting
say the percentage change in stock price movements, to color +ve points in
green and -ve points in red? And extending this to a user-defined range of
colors based on the quartile of the data points?
Thanks
Rory
Rory Winston
RBS Global Banking & Markets
280 Bishopsgate, London, EC2M 4RB
Office: +44 20 7085 4476
****************************************************************************
*******
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered
Office: 36 St Andrew Square, Edinburgh EH2 2YB.
Authorised and regulated by the Financial Services Authority
This e-mail message is confidential and for use by =\ th...{{dropped:10}}
FWIW Indeed! And IMHO such a nice example of the power and beauty of the R language. -- Bert -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Greg Snow Sent: Tuesday, November 25, 2008 10:00 AM To: Rory.WINSTON at rbs.com; r-help at r-project.org Subject: Re: [R] Line color based on data values? Try this: tmp <- with(iris, seq( min(Petal.Length)-1, max(Petal.Length)+1, length.out=6)) with( iris, plot( Sepal.Width, Sepal.Length, col=topo.colors(5)[ cut(Petal.Length,tmp) ] ) ) hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Rory.WINSTON at rbs.com > Sent: Tuesday, November 25, 2008 10:35 AM > To: r-help at r-project.org > Subject: [R] Line color based on data values? > > Hi all > > Does anyone know if it is possible when plotting a line or scatter > plot, to selectively color the data points based on the data value? > i.e. if plotting say the percentage change in stock price movements, to > color +ve points in green and -ve points in red? And extending this to > a user-defined range of colors based on the quartile of the data > points? > > Thanks > Rory > > Rory Winston > RBS Global Banking & Markets > 280 Bishopsgate, London, EC2M 4RB > Office: +44 20 7085 4476 > > > > *********************************************************************** > ************ > The Royal Bank of Scotland plc. Registered in Scotland No 90312. > Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB. > Authorised and regulated by the Financial Services Authority > > This e-mail message is confidential and for use by > the=2...{{dropped:25}} > > ______________________________________________ > 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.