【发布时间】:2021-11-22 04:41:57
【问题描述】:
我正在使用 ggplot 创建分类条形图,但我需要更改堆叠段的布局。这是我创建情节的代码:
ggplot(full_genus_new, aes(x=as.factor(Var2), y=value, fill=Var1)) +
geom_bar(stat="identity", position = "fill", aes(order = -value)) +
scale_x_discrete() +
ylab("Relative Microbial Activity") +
facet_grid(cols=vars(PEDIS), scales = "free_x", space = "free_x") +
theme_classic() +
scale_fill_manual(values = Cb64k) +
scale_y_continuous(labels=percent_format()) +
theme(legend.position = "bottom", legend.text = element_text(size=8)) +
guides(fill=guide_legend(title="Taxa")) +
xlab("Patient") +
theme(legend.key.size = unit(0.5,'cm'))
这会产生以下内容:
如何使“其他”组位于堆栈底部而不是中间,以使图像看起来更干净?
这就是我正在使用的数据框的外观,它是一个高大的结构,Var2 是患者:
【问题讨论】: