Guest User

Untitled

a guest
Dec 11th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. df <- data.frame(Make=c('toyota','toyota','honda','honda','jeep','jeep','jeep','accura','accura'),
  2. Model=c('camry','corolla','city','accord','compass', 'wrangler','renegade','x1', 'x3'),
  3. Cnt=c(10, 4, 8, 13, 3, 5, 1, 2, 1))
  4. row_threshold = 2
  5. dfc <- df %>%
  6. group_by(Make) %>%
  7. summarise(volume = sum(Cnt)) %>%
  8. mutate(share=volume/sum(volume)*100.0) %>%
  9. arrange(desc(volume))
  10.  
  11.  
  12. dfc$Make <- factor(dfc$Make, levels = rev(as.character(dfc$Make)))
  13. pie <- ggplot(dfc[1:10, ], aes("", share, fill = Make)) +
  14. geom_bar(width = 1, size = 1, color = "white", stat = "identity") +
  15. coord_polar("y") +
  16. geom_text(aes(label = paste0(round(share), "%")),
  17. position = position_stack(vjust = 0.5)) +
  18. labs(x = NULL, y = NULL, fill = NULL,
  19. title = "Market Share") +
  20. guides(fill = guide_legend(reverse = TRUE)) +
  21. theme_classic() +
  22. theme(axis.line = element_blank(),
  23. axis.text = element_blank(),
  24. axis.ticks = element_blank(),
  25. plot.title = element_text(hjust = 0.5, color = "#666666")) +
  26. scale_color_brewer(palette = "Paired")
Add Comment
Please, Sign In to add comment