[R] Color barplots with a conditional?
R. Michael Weylandt <michael.weylandt@gmail.com>
michael.weylandt at gmail.com
Thu Sep 15 02:40:35 CEST 2011
You've almost got it. If your category variables are factors, then adding col=data$category to plot() will do it automatically since factors will be coerced to their integer representation. If you want a different color map, you can do arithmetic transformations on the integer codings directly as well.
Let me know if I can clarify this further.
Michael Weylandt
On Sep 14, 2011, at 4:14 PM, Allie818 <alice.ly at gmail.com> wrote:
> I've made a barplot that has several bars. I'd like the bars to be colored
> according to the type of category they are in. Is there a way to put a
> conditional into the color parameter in barplot?
> i.e. if data$category[i] == 1, color the bar red
>
> Do I need to generate the coloring sequence before the plot code first?
>
> Thanks!!
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Color-barplots-with-a-conditional-tp3813990p3813990.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.
More information about the R-help
mailing list