0

Is there a quick and easy way to produce a bar chart from this type of output? Wasn't sure if I could do it without reshaping the data or a separate dplyr statement.

res <-
  df %>%
  mutate(categoryName = factor(categoryName, levels = c('Not Applicable', 'Very Poor', 'Bad', 'OK', 'Good', 'Very Good'))) %>%
  group_by(categoryName) %>%
  count() %>%
  adorn_totals('row') %>%
  spread(categoryName, n) %>%
  mutate(Yes = `OK` + `Good` + `Very Good`)

res

Output looks like this (I redacted the tibble numbers for privacy but all are positive ints). I wouldn't grab the 'Yes' or 'Total' column (needed those for a (Yes/Total)% calculation).

enter image description here

zelda26
  • 489
  • 2
  • 10
  • 33
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Dec 06 '19 at 21:49

1 Answers1

1

This should work for you:

res %>% 
  gather("Rating",'Instances') %>% 
  filter(Rating %in% c('Not Applicable', 'Very Poor', 'Bad', 'OK', 'Good', 'Very Good')) %>%
  ggplot(aes(x=Rating,y=Instances)) + 
  geom_bar(stat='identity')
ErrorJordan
  • 611
  • 5
  • 15