[英]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")
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.