For the first question you can use %in% rather than ==, for example:
ifelse( dataframe$vector_o_number %in% c('00','01), 'red',
'black')
for the reference line, the abline function will draw a line the full
width/height of a graph for a general reference, if you want separate lines for
each group of bars then the segments function will draw the shorter lines. Note
that the return value of the barplot function gives information on the x
coordinates of the bars that could be useful in drawing the lines (see the
examples for barplot).
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 John Malone
> Sent: Wednesday, February 25, 2009 7:05 PM
> To: r-help at r-project.org
> Subject: [R] two colors and putting lines on bar plots
>
> Hi all,
>
> I want to represent two categories with one color and have other
> categories
> a different color on a bar plot.
>
> I can do this using for one category/number using the ifelse call in
> col but
> how to extend to two categories/numbers?
>
> barplot(dataframe$vector_o_numbers,
> col=ifelse(dataframe$vector_o_numbers => 00, "red",
"black"), names.arg=dataframe$labels)
>
> For example if I wanted to label 00 and 01 red and have the rest of the
> categories colored black....how to do this?
>
> Finally........I'd Iike to put a line on the bar plot representing an
> expected number to compare to the observed number for a particular
> category.
> In the past I've done this by drawing a line manually on a graph using
> photoshop or something similar. Is there way to do this in R?
>
> Many thanks all in advance for your help!!
>
> John
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.