[R] Plot using colors

hadley wickham h.wickham at gmail.com
Mon Mar 3 15:50:04 CET 2008


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/



More information about the R-help mailing list