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?
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.
theme_gray() Using themes, you can change the colors and styles of the borders, backgrounds, lines, and text on a plot.
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.
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”.
You have to put colour
outside aes
:
ggplot(test) + geom_bar(aes(x=a, y=b, fill=c), colour="black", stat="identity")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With