Home > OS >  Colouring histogram splits it up
Colouring histogram splits it up

Time:04-06

When I add an outline colour to my histogram, and fill in the colours it looks like this: enter image description here

Here's the code that I am using:

ggplot(mtcars, aes(as.character(cyl), log(hp), fill = as.character(cyl)))   
    geom_col(colour=1,alpha = 0.75)  
    scale_fill_manual(values = c("gray", "red", "blue"))

How can I remove the horizontal lines for each plot so it remains as a single block with one colour? When I remove colour=1 I get what I'm after, but I need the black colour outlines for each block.

CodePudding user response:

I suggest using stat_summary instead, and making use of fun = "sum"

ggplot(mtcars, aes(as.character(cyl)))   
  stat_summary(aes(y = log(hp), fill = as.character(cyl)), fun = "sum", geom = "bar", colour = "black")  
  scale_fill_manual(values = c("gray", "red", "blue"))

enter image description here

  • Related