简体   繁体   English

ggplot2-geom_bar带边框= NA

[英]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. 我正在尝试使用ggplot2生成堆积图, ggplot2无法消除条形图之间的白色细线。

With the base barplot function, using the argument border = NA gives me what I want (figure on the right) 使用基本的barplot函数时,使用border = NA参数可以得到所需的信息(右图)

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. 但是,我无法通过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()

在此处输入图片说明

Any idea? 任何想法?

I don't want the geom_area solution 我不想要geom_area解决方案

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 . geom_bar层中的width设置为0.9 If you set it to 1.0 the bars will fill the space and the borders will disappear. 如果将其设置为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()

情节

From the geom_bar documentation: geom_bar文档中:

width Bar width. 宽度栏宽度。 By default, set to 90% of the resolution of the data. 默认情况下,设置为数据分辨率的90%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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