【发布时间】:2021-07-08 14:39:23
【问题描述】:
我有如下所示的代码,我现在想在基于n 订购条形图时绘制obstacles (x) 和n (y),所以我继续执行以下操作:
library(tidyverse)
move_obstacles = tibble::tribble(
~move_approach, ~obstacle, ~n,
"Relocate", "Distance from business activities", 1L,
"Relocate", "No customers", 1L,
"Relocate", "No services", 1L,
"Upgrade Existing", "Cost of move", 4L,
"Upgrade Existing", "Distance from business activities", 6L,
"Upgrade Existing", "Higher rent", 1L,
"Upgrade Existing", "Higher taxes", 2L,
"Upgrade Existing", "No customers", 6L,
"Upgrade Existing", "No services", 3L
) %>%
ggplot(aes(reorder(obstacle,n),n)) +
geom_col() +
theme_bw() +
coord_flip() +
xlab(NULL) +
ylab(NULL) +
ggtitle("Obstacles to moving")
move_obstacles
由reprex package (v2.0.0) 于 2021-07-08 创建
如您所见,即使我包含了重新排序 ggplot(aes(reorder(obstacle,n),n)) 的代码,条形也不是按数量级排列的。
我该如何解决这个问题?
【问题讨论】: