Guest User

Untitled

a guest
Nov 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. df <- data.frame(site=c("GA","NY","BO","NY","BO","NY","BO","NY","BO","GA","NY","GA","NY","NY","NY"),purchase=c("a1","a2","a1","a1","a3","a1","a1","a3","a1","a2","a1","a2","a1","a2","a1"),happycustomer=c("n","y","n","y","y","y","n","y","n","y","y","y","n","y","n"))
  2.  
  3. library(ggplot2)
  4. library(dplyr)
  5. df %>%
  6. group_by(site, purchase,happycustomer) %>%
  7. summarize(bin = sum(happycustomer==happycustomer)) %>%
  8. group_by(site,happycustomer) %>%
  9. mutate(bin_per = (bin/sum(bin)*100)) %>%
  10. ggplot(aes(site,purchase)) + geom_tile(aes(fill = bin_per),colour = "white") + geom_text(aes(label = round(bin_per, 1))) +
  11. scale_fill_gradient(low = "blue", high = "red")
Add Comment
Please, Sign In to add comment