Hi, I am using barplot and would like to know if it is possible to have bars filled with one color while use a different color for the shading lines. The following code colors the shading lines, leaving the bars in white: barplot(1:5, col=c(1:5), density=c(1:5)*5) while the colors are applied to the bars when density is removed. barplot(1:5, col=c(1:5)) I did check ?barplot and found the following: col: a vector of colors for the bars or bar components. Thanks, Hao --
Marc Schwartz
2006-Sep-07 12:54 UTC
[R] barplot: different colors for the bar and the strips
On Thu, 2006-09-07 at 06:18 -0500, Hao Chen wrote:> Hi, > > I am using barplot and would like to know if it is possible to have bars > filled with one color while use a different color for the shading lines. > > The following code colors the shading lines, leaving the bars in white: > > barplot(1:5, col=c(1:5), density=c(1:5)*5) > > while the colors are applied to the bars when density is removed. > > barplot(1:5, col=c(1:5)) > > I did check ?barplot and found the following: > > col: a vector of colors for the bars or bar components. > > Thanks, > > HaoNote the key word 'or' in the description of the 'col' argument. You need to make two separate calls to barplot(). The first using the fill colors, then the second using the shading lines AND setting 'add TRUE', so that the second plot overwrites the first without clearing the plot device. barplot(1:5, col=c(1:5)) barplot(1:5, col = "black", density=c(1:5), add = TRUE) Just be sure that any other arguments, such as axis limits, are identical between the two calls. HTH, Marc Schwartz