如何添加一个彩色轮廓barmekko酒吧

5f0d552i  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(77)

我有一个问题的颜色的轮廓的酒吧,我试图添加一个黑色的轮廓,它仍然出现相同的,我试图使一个类似的图形与ggplot2,但mekko库是一个最适合它,我试图添加函数。geom_bar()geom_col()例如geom_bar(stat = "identity", position = "fill", color = "black"),但没有变化。

library(ggpubr)
library(gridExtra)
library(egg)
library(mekko)
library(lemon)
library(ggh4x)

plotq<- data.frame(product = c(51.7,65.5,6.9, 27.6,13.8),
                  profit_margin = c(24.6, 70.2,1.3 ,1.3, 0.5),
                  D= c(32.8,33.6,2.6,12.1,5.2),
                  revenue = c(51.7,65.5,6.9, 27.6,13.8))

NUMER <- barmekko(plotq, product, profit_margin,revenue) +
  scale_fill_manual(values = c("#8DFF47","#FF9BB1","#FF974C","#F1FF54","#BFFAFF"))+
  scale_y_continuous(expand = expansion(mult = c(0, 0.5))) + 
  theme_bw()+
  theme(axis.title.x = element_blank(), axis.text.x = element_blank()) +
  theme(axis.ticks.length.x = unit(0, "cm")) +
  theme(plot.margin = unit(c(0,0,0,0), "cm"))

GRAVIM <- barmekko(plotq, product, D,revenue)+
  scale_fill_manual(values = c("#8DFF47","#FF9BB1","#FF974C","#F1FF54","#BFFAFF"))+
  scale_y_reverse(expand = expansion(mult = c(0.5, 0))) +
  theme_bw() + theme(legend.position = "none") +
  theme(plot.margin = unit(c(0,0,0,0), "cm"))

ggarrange(NUMER, GRAVIM, nrow = 2)

字符串


的数据

thtygnil

thtygnil1#

由于barmekko()函数不允许任何自定义,因此可以直接操作返回的ggplot对象来添加黑色轮廓,如下所示:

library(ggplot2)
library(ggpubr)
library(mekko)

NUMER$layers[[1]]$aes_params$colour <- "black"
GRAVIM$layers[[1]]$aes_params$colour <- "black"

ggarrange(NUMER, GRAVIM,
  nrow = 2,
  common.legend = TRUE, legend = "right",
  align = "v"
)

字符串


的数据

相关问题