简体   繁体   中英

ggplot2 - geom_bar with border = NA

I am trying to produce stacked plots with ggplot2 and I can't get rid of white thin lines between bars.

With the base barplot function, using the argument border = NA gives me what I want (figure on the right)

barplot(df, border = NA, space = 0, col = c('orange', 'khaki'), main = 'border = NA')

在此处输入图片说明

However, I can't figure out with ggplot2 to get these borders to disappear.

library(ggplot2) 
library(dplyr) 
library(broom) 
library(reshape2) 

df %>% melt() %>% ggplot(aes(Var2, value, fill = factor(Var1))) + 
  geom_bar(stat = 'identity',  width=0.9) + 
  scale_fill_manual(values = c('orange', 'khaki')) + theme_minimal()

在此处输入图片说明

Any idea?

I don't want the geom_area solution

geom_area(stat = 'identity',  position = "stack")

the data

sq = round( sort(rnorm(100, 50, 10)))  
df = matrix(0, 2, 100)
df[1, ] = sq
df[2, ] = 100 - sq

The width in the geom_bar layer is set to 0.9 . If you set it to 1.0 the bars will fill the space and the borders will disappear.

df %>% melt() %>% ggplot(aes(Var2, value, fill = factor(Var1))) + 
  geom_bar(stat = 'identity', width = 1) + 
  scale_fill_manual(values = c('orange', 'khaki')) + theme_minimal()

情节

From the geom_bar documentation:

width Bar width. By default, set to 90% of the resolution of the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM