Guest User

Untitled

a guest
Oct 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. library(ggplot2)
  2.  
  3. Unit <- c("A", "B", "C", "D") #character objects need quotes
  4. Yes <- c(50, 65, 20, 41)
  5. No <- c(70, 67, 40, 20)
  6. Missing <- c(10, 12, 8, 7)
  7. df <- data.frame(Unit, Yes, No, Missing)
  8.  
  9. require(tidyr)
  10. df.long <- gather(df, Unit)
  11. colnames(df.long) <- c("Unit", "variable", "value")
  12.  
  13. ggplot(data = df.long, aes(x = Unit, y = value, fill = variable)) +
  14. geom_col(position = position_dodge())
Add Comment
Please, Sign In to add comment