Not that straight forward but ordering within facets is posible with the help of this functions written by David Robinson.
library(tidyverse)
library(scales)
cols <- c('Good' = '#1a9641',
'OK' = '#a6d96a',
'Bad' = '#fdae61',
'Remove' = '#d7191c')
dummy_groups <- map2(names(cols), c(10, 3, 1, 1), ~ rep(.x, .y)) %>% unlist()
reorder_within <- function(x, by, within, fun = mean, sep = "___", ...) {
new_x <- paste(x, within, sep = sep)
stats::reorder(new_x, by, FUN = fun)
}
scale_x_reordered <- function(..., sep = "___") {
reg <- paste0(sep, ".+$")
ggplot2::scale_x_discrete(labels = function(x) gsub(reg, "", x), ...)
}
missingness_by_vore <- msleep %>%
gather(key ='feature', value = 'value', -vore) %>%
add_count(vore, feature,
wt = is.na(value),
name = 'num_missing') %>%
add_count(vore, feature,
name = 'num_rows') %>%
mutate(pct_missing = num_missing / num_rows) %>%
distinct(vore,
feature,
num_missing,
pct_missing) %>%
mutate(Group = map_chr(ntile(pct_missing, length(dummy_groups)),
~ pluck(dummy_groups, .x)))
ggplot(missingness_by_vore,
aes(x = reorder_within(feature, desc(num_missing), vore),
y = num_missing,
fill = Group)) +
geom_col() +
geom_text(aes(label = scales::percent(pct_missing) %>%
modify_if(. == '0.0%', ~ '')),
nudge_y = 2, size = 2) +
scale_fill_manual(values = cols,
breaks = names(cols)) +
coord_flip() +
labs(x = 'Features',
y = 'Number of missing rows') +
scale_x_reordered() +
facet_wrap(vars(vore), scales = "free_y") +
theme_minimal()

Created on 2019-03-14 by the reprex package (v0.2.1)
This is the link to the github repo for this functions