Graph with ordered bars and using facets

前端 未结 2 1059
盖世英雄少女心
盖世英雄少女心 2021-01-22 23:28

I am trying to make a graph with ordered bars according to frequency and also using a variable two separate two variables using facets. Words have to be ordered by value

2条回答
  •  终归单人心
    2021-01-23 00:04

    Given the info provided by @GordonShumway and following the answer given by @CPak, bellow I provide the entire and "tricky" and no-elegant way to fix this issue. The almost entire answer (by @CPak) and one more line finally fix the problem:

    d %>%
      mutate(temp = paste(word, u_c, sep = "_")) %>%
      ggplot(aes(x = fct_reorder(temp, n), y = n, fill = u_c)) +
      geom_col(show.legend = F) +
      scale_x_discrete(labels = function(x) str_replace(x,"_candidate|_user", "")) +
      facet_wrap(~u_c, scales = "free_y") + 
      coord_flip()
    

    Thanks for the answers!

提交回复
热议问题