r - 无法对列重新排序 (fct_reorder())
问题描述
我正在尝试重新排序列以获得降序列的形成。我到目前为止的情节附在下面:
理想情况下,情节应该是这样的,但仍充满专家级别。
这是我到目前为止的 R 代码:
# !!!
survey_data_barchart %>%
dplyr::filter(!is.na(expert.level)) %>%
dplyr::filter(!is.na(country)) %>%
group_by(expert.level) %>%
count(country) %>%
# mutate(country = fct_reorder(country, n)) %>%
ggplot(aes(x = reorder(country, +n), n, fill = expert.level)) +
geom_bar(stat = "identity") +
coord_flip() +
theme(legend.position="top",
axis.text.x = element_text(size = 20, vjust = 1.3),
axis.text.y = element_text(size = 15),
legend.title = element_blank(),
axis.ticks = element_blank(),
# axis.title.y = element_blank(),
# axis.title.x = element_blank(),
rect = element_blank(),
legend.text = element_text(size=25),
axis.title.x = element_text(size=20, vjust = 0.5)) +
guides(fill = guide_legend("")) +
labs(x = "",
y = "Responses") +
scale_fill_brewer(palette = "Set2")
#scale_x_discrete(guide = guide_axis(n.dodge = 2))
进入 ggplot 表达式的数据如下所示:
# A tibble: 104 × 3
# Groups: expert.level [5]
expert.level country n
<chr> <chr> <int>
1 Anaesthesia technician Belgium 2
2 Anaesthesia technician Greece 1
3 Anaesthesia technician Moldova 1
4 Anaesthesia technician Romania 2
5 Anaesthesia technician Russia 3
6 Anaesthesia technician Switzerland 1
7 Consultant Albania 3
8 Consultant Austria 24
9 Consultant B&H 4
10 Consultant Belarus 1
感谢您的帮助,祝您周末愉快!
格里戈里
解决方案
推荐阅读
- python - 编写一个python程序来反转给定的数字
- javascript - 基于这个 SVG 我如何将颈部区域与头部隔离
- python - 不能在共享驱动器上导入吗?
- java - Mocikto 如何正确验证模拟调用
- sql - 在 WHERE 子句中调整 DECODE() 语句的性能
- java - 无法在未调用 Looper.prepare() 的线程 Thread[create_react_context,5,main] 中创建处理程序
- c++ - 是否建议将 =default 析构函数与空构造函数一起使用?
- javascript - 如何将javascript代码更改为angular中的打字稿
- angular - 在 CF 上部署时出错:“ERR 服务命令需要在 Angular 项目中运行,但找不到项目定义。”
- java - 当我关闭数据库时,永远不会从 Spring JPA 调用 TransactionException - 为什么?