Dear R users, I have a problem since I try to plot my datas with different colors. plot(tvar, var, xlab="zeit [s]",ylab="Variation [%]", col = ifelse(var <varstability, 'green','red')) this works well! But since I add a type="l" to my plot, it will color all the plot with green!!! Is there any solution? I avoid to use teachingDemos. Thanks. -- View this message in context: http://www.nabble.com/Plot-using-colors-tp15799930p15799930.html Sent from the R help mailing list archive at Nabble.com.
On Mon, Mar 03, 2008 at 02:03:07AM -0800, mysimbaa wrote:> > Dear R users, > I have a problem since I try to plot my datas with different colors. > > plot(tvar, var, xlab="zeit [s]",ylab="Variation [%]", col = ifelse(var <> varstability, 'green','red')) > this works well! > > But since I add a type="l" to my plot, it will color all the plot with > green!!!Please include this too. -- Hans Ekbrand (http://sociologi.cjb.net) <hans at sociologi.cjb.net> GPG Fingerprint: 1408 C8D5 1E7D 4C9C C27E 014F 7C2C 872A 7050 614E -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: Digital signature Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080303/0ff7dd8e/attachment.bin
You want just the points with colors? var <- rnorm(10) vars <- rnorm(10) plot(var, type='l') points(var, col=ifelse(var < vars, 'green', 'red'), pch= 16) or the lines also? for(i in 1:9)segments(i, var[i], i + 1, var[i+1], ifelse(var[i] < vars[i], 'green', 'red')) On 03/03/2008, mysimbaa <adel.tekari at sisltd.ch> wrote:> > Dear R users, > I have a problem since I try to plot my datas with different colors. > > plot(tvar, var, xlab="zeit [s]",ylab="Variation [%]", col = ifelse(var <> varstability, 'green','red')) > this works well! > > But since I add a type="l" to my plot, it will color all the plot with > green!!! > Is there any solution? I avoid to use teachingDemos. > > Thanks. > -- > View this message in context: http://www.nabble.com/Plot-using-colors-tp15799930p15799930.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
On Mon, Mar 3, 2008 at 4:03 AM, mysimbaa <adel.tekari at sisltd.ch> wrote:> > Dear R users, > I have a problem since I try to plot my datas with different colors. > > plot(tvar, var, xlab="zeit [s]",ylab="Variation [%]", col = ifelse(var <> varstability, 'green','red')) > this works well! > > But since I add a type="l" to my plot, it will color all the plot with > green!!! > Is there any solution? I avoid to use teachingDemos.You might want to look at ggplot2, http://had.co.nz/ggplot2, which provides many tools to make this type of mapping easy. For example, library(ggplot2) qplot(tvar, var, colour=varstability, geom="line") might be sufficient in your case (although without a minimal reproducible example it's impossible to know) Hadley -- http://had.co.nz/