geom_bar define border color of entire column instead of individual block

57 Views Asked by At

I want to draw a stacked bar plot using ggplot with blue outline. However, my code will draw all blocks with blue outline. I would want only the entire column with blue outline not lines inside the column. Here's my code. In this example, I want to remove blue line between my red block and green block.

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="blue", stat="identity")

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

One option would be to draw a second transparent barchart with a blue outline on top the first where I use stat="summary" with fun=sum to compute the totals for each a:

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), stat = "identity") +
  geom_bar(
    aes(x = a, y = b, group = a),
    colour = "blue", 
    stat = "summary", fun = sum,
    fill = "transparent"
  )