Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

geom_bar define border color with different fill colors

Tags:

I want to draw a bar plot with geom_bar where I want unique fill colors surrounded by a black border. However the instruction color="black" is not interpreted as "black" as I want it to be and I get red borders.

library(ggplot2) test=as.data.frame(cbind(a=c(1,1,2,3), b=1:4, c=as.character(1:4))) ggplot(test) + geom_bar(aes(x=a, y=b, fill=c, colour="black"), stat="identity") 

How do I correctly use geom_bar so that it gives me the correct black border?

like image 970
mts Avatar asked Jun 08 '15 13:06

mts


People also ask

How do I change the color of a border in R?

To change the plot border color of a ggplot2 graph in R, we can use theme function with panel. background argument where we can set the border of the plot panel using element_rect to desired color.

Which parameter of the Qplot () function changes the border color?

theme_gray() Using themes, you can change the colors and styles of the borders, backgrounds, lines, and text on a plot.

How do I make bars different colors in R?

R barplot() – Set Colors for Bars in Bar Plot To set colors for bars in Bar Plot drawn using barplot() function, pass the required color value(s) for col parameter in the function call. col parameter can accept a single value for color, or a vector of color values to set color(s) for bars in the bar plot.

Which attribute will you use to add boundary color to the bar plot?

To manually change the color of a bar plot we will use the following function : scale_fill_manual( ) : It is used to provide custom colors. We can either write the color code as “#XXXXXX” or we can directly write the color name as “color_name”.


1 Answers

You have to put colour outside aes:

ggplot(test) + geom_bar(aes(x=a, y=b, fill=c), colour="black", stat="identity") 

enter image description here

like image 73
zero323 Avatar answered Jan 02 '23 15:01

zero323