Hi all, I am a new user of R. I just did my first real program. I would like to know how to put a gradient (like rainbow() or topo.colors, etc) to a* line* graph. Example: ar1=array(data=1:10,dim=9) ar2=array(data=11:20,dim=9) plot(ar1,ar2,type="l",col="red",lwd=3) Instead of a red color, I would like to make it in rainbow colors. Tried to do my own and tried searching but everywhere its about giving gradient to point graph, not to a line graph. Please help, it is needed for my work. Thanks in advance -- Riyas MJ Project assistant (PA -II) Physical Oceanography Department (POD) CSIR- National Institute of Oceanography (NIO) Dona Paula, Goa - 403 004, India Ph: +91 9037553320, +91 7083030397 [[alternative HTML version deleted]]
> On Feb 4, 2017, at 9:14 AM, Riyas MJ <riyasmjgeo at gmail.com> wrote: > > Hi all, > > I am a new user of R. I just did my first real program. > I would like to know how to put a gradient (like rainbow() or topo.colors, > etc) to a* line* graph. > > Example: > ar1=array(data=1:10,dim=9) > ar2=array(data=11:20,dim=9) > plot(ar1,ar2,type="l",col="red",lwd=3) > > Instead of a red color, I would like to make it in rainbow colors. > Tried to do my own and tried searching but everywhere its about giving > gradient to point graph, not to a line graph. Please help, it is needed forInstall the plotrix package and look in its Index page for a function name that has both `color` and `line` in its name. -- David.> my work. > > Thanks in advance > -- > Riyas MJ > Project assistant (PA -II) > Physical Oceanography Department (POD) > CSIR- National Institute of Oceanography (NIO) > Dona Paula, Goa - 403 004, India > Ph: +91 9037553320, +91 7083030397 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.David Winsemius Alameda, CA, USA
You haven't indicated what information you want to convey with this gradient. You also are using arrays where you should be using vectors, usually stored in a data frame. Here is one way using the contributed package ggplot2: library(ggplot2) DF <- data.frame( V1=1:10, V2=11:20, C=21:30 ) p <- ggplot( DF, aes( x=V1, y=V2, colour=C ) ) + geom_line( size=2 ) + scale_colour_gradient( low="red", high="blue" ) print( p ) -- Sent from my phone. Please excuse my brevity. On February 4, 2017 12:19:14 PM PST, David Winsemius <dwinsemius at comcast.net> wrote:> >> On Feb 4, 2017, at 9:14 AM, Riyas MJ <riyasmjgeo at gmail.com> wrote: >> >> Hi all, >> >> I am a new user of R. I just did my first real program. >> I would like to know how to put a gradient (like rainbow() or >topo.colors, >> etc) to a* line* graph. >> >> Example: >> ar1=array(data=1:10,dim=9) >> ar2=array(data=11:20,dim=9) >> plot(ar1,ar2,type="l",col="red",lwd=3) >> >> Instead of a red color, I would like to make it in rainbow colors. >> Tried to do my own and tried searching but everywhere its about >giving >> gradient to point graph, not to a line graph. Please help, it is >needed for > >Install the plotrix package and look in its Index page for a function >name that has both `color` and `line` in its name.