簡體   English   中英

ggplot2-geom_bar帶邊框= NA

[英]ggplot2 - geom_bar with border = NA

我正在嘗試使用ggplot2生成堆積圖, ggplot2無法消除條形圖之間的白色細線。

使用基本的barplot函數時,使用border = NA參數可以得到所需的信息(右圖)

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

在此處輸入圖片說明

但是,我無法通過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()

在此處輸入圖片說明

任何想法?

我不想要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

geom_bar層中的width設置為0.9 如果將其設置為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()

情節

geom_bar文檔中:

寬度欄寬度。 默認情況下,設置為數據分辨率的90%。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM