library(tidyverse)

df <- read.table(text = "Name   WT  Mutant
'cellular process'  200 2
'Biological phase'  150 5
'cell process'  100 9", header = TRUE)

df %>%
  pivot_longer(-Name) %>%
  ggplot(aes(x = Name, y = value, fill = name)) +
  geom_col(position = position_stack()) +
  coord_flip() +
  facet_wrap(~name)

Using the above code i am unable to change the group position in the graph.enter image description here

我需要WT组第一,变种人组第二.提前感谢您的帮助.

如上所述,我需要改变该小组的立场.非常感谢你的帮助.

推荐答案

一种解决方案是将水平设置为name

df %>%
  pivot_longer(-Name) %>%
  mutate(name = factor(name, levels=c("WT", "Mutant"))) %>% 
  ggplot(aes(x = Name, y = value, fill = name)) +
  geom_col(position = position_stack()) +
  coord_flip() +
  facet_wrap(~name)

enter image description here

R相关问答推荐

R Tidymodels textercipes-使用spacyR进行标记化-如何从生成的标记列表中删除标点符号

在另一个函数中调用ggplot2美学

如何在R中对深度嵌套的tibbles中的非空连续行求和?

移除仪表板Quarto中顶盖和车身之间的白色区域

矩阵的堆叠条形图,条形图上有数字作为标签

R spatstat Minkowski Sum()返回多个边界

将二进制数据库转换为频率表

R中1到n_1,2到n_2,…,n到n_n的所有组合都是列表中的向量?

在R中,我如何使用滑动窗口计算位置,然后进行过滤?

如何对r中包含特定(未知)文本的行求和?

创建在文本字符串中发现两个不同关键字的实例的数据框

整理曲线图、曲线图和点图

是否有一个R函数可以输出在输入的字符向量中找到的相应正则表达式模式?

如何从嵌套数据中自动创建命名对象?在R中

Broom.Mixed::Augment不适用于Sample::分析

如何创建一个由一个连续变量和一个因素变量组成的复杂方框图?

用逗号拆分字符串,并删除一些字符

移除y轴断开的geom_bar图的外框

迭代通过数据帧创建直方图

看似重叠的剧情