Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. # Some R code to demo boxplots, beanplots, pirateplots, etc
  2.  
  3. library(psych)
  4. library(dplyr)
  5. library(tidyr)
  6. library(beanplot)
  7. library(yarrr)
  8.  
  9. # Load the cushny data
  10. data(cushny)
  11.  
  12. # Plot it using error.bars. Following example in psych package manual
  13. error.bars(cushny[1:4],
  14. within=TRUE,
  15. ylab="Hours of sleep",
  16. xlab="Drug condition",
  17. main="95% confidence of within subject effects")
  18.  
  19. # Reformat the data into a "long" and "tidy" format
  20. Df <- select(cushny, Control, drug1, drug2L, drug2R) %>%
  21. mutate(subject = factor(seq(length(Control)))) %>%
  22. select(subject, everything()) %>%
  23. gather(drug, sleep, Control:drug2R) %>%
  24. arrange(subject)
  25.  
  26. # A box plot
  27. boxplot(sleep ~ drug,
  28. data=Df,
  29. ylab='Hours of sleep',
  30. xlab='Drug')
  31.  
  32. # Beanplot
  33. beanplot(sleep ~ drug,
  34. data=Df,
  35. ylab='Hours of sleep',
  36. xlab='Drug',
  37. col='lightgray',
  38. overallline = 'median')
  39.  
  40. # Pirateplot
  41. pirateplot(formula = sleep ~ drug,
  42. data = Df,
  43. theme = 3,
  44. point.o = 1,
  45. ylab='Hours of sleep',
  46. xlab='Drug')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement