2017-04-16 109 views
1

我试图用ggplot2来制作堆积图,我无法摆脱白色条间的细线。ggplot2 - geom_bar的边框=不适用

随着基地barplot功能,使用参数border = NA给我我想要的(上右图)

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

enter image description here

不过,我想不出有ggplot2得到这些边界消失。

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() 

enter image description here

任何想法?

我不想geom_area解决方案

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

数据

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

回答

2

geom_bar层设置为0.9width。如果将其设置为1.0,则条形将填充该空间,边框将消失。

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

plot

From the geom_bar documentation:

宽度酒吧宽度。默认情况下,设置为数据分辨率的90%。

+1

非常感谢 – giacomo