如何使一个方面内的行根据另一个向量的级别出现?

How to make the rows within a facet appear according to the level of another vector?

目标是在每个构面内从上到下显示“name”和“startTime”。方面A是错误的;方面 B 是正确的。

library(tidyverse)
my_tribble <- tribble(
  ~name, ~order.x,  ~startTime, ~endTime, ~order.y, ~endTime.y, ~diff, ~area,
  "unit1", "dump", 0, 1, "wait", 2, 2, "A",
  "unit3", "dump", 5, 7, "wait", 9, 4, "A",
  "unit4", "dump", 8, 9, "wait", 10, 2, "B",
  "unit2", "dump", 17, 20, "wait", 23, 6, "B"
)

ggplot(my_tribble) +
  geom_linerange(aes(ymin = startTime, ymax = endTime.y, x = name),position = position_dodge(width = 0.2), size = 2) +
  facet_grid(area ~ ., scales = "free_y") +
  coord_flip() +
  scale_x_reordered() +
  scale_y_continuous(expand = c(0,0))

my_tribble$name <- factor(my_tribble$name, levels = my_tribble$name[order(-my_tribble$startTime)])
ggplot(my_tribble) +
  geom_linerange(aes(ymin = startTime, ymax = endTime.y, x = name),position = position_dodge(width = 0.2), size = 2) +
  facet_grid(area ~ ., scales = "free_y") +
  coord_flip() +
  scale_y_continuous(expand = c(0,0))