ggvis - Interactive X axis for bar chart

前端 未结 1 1683
温柔的废话
温柔的废话 2020-12-18 03:51

I\'m looking into building a shiny app with ggvis. For this I\'m using a small dataset called \"company\". It contains employee data where each line represents and employee.

相关标签:
1条回答
  • 2020-12-18 04:25

    First of all you need to melt your data.frame like this:

    library(reshape2)
    company <- melt(company, measure.vars=c('Role','Age','Sex'))
    

    And then the following worked for me:

    #Barcharts - Age
    company %>% ggvis(~value, opacity := 0.8) %>%
      #use filter to pick only the category you want
      filter(variable == eval(input_select(choices=c('Role','Age','Sex')))) %>%
      layer_bars()
    

    I cannot upload the interactive version but the plot looks like this:

    enter image description here

    And you can pick the category you like

    0 讨论(0)
提交回复
热议问题