Graph with ordered bars and using facets

前端 未结 2 1083
盖世英雄少女心
盖世英雄少女心 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-22 23:54

    The very relevant comment aside by GordonShumway (because the solution offered there is a little black magicky) - you can create a temporary value to reorder your facet - note I'm using forcats::fct_reorder rather than reorder

    library(tidyverse)
    d %>%
      mutate(temp = paste0(word, u_c)) %>%
      ggplot(aes(x = fct_reorder(temp, n), y = n, fill = u_c)) +
      geom_col(show.legend = F) +
      facet_wrap(~u_c, scales = "free_y") + 
      coord_flip()
    

提交回复
热议问题