Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. boxplot(cost ~ type)
  2.  
  3. ----- -----
  4. | |
  5. [ ] |
  6. | [ ]
  7. | |
  8. ----- -----
  9. A B
  10.  
  11. bymedian <- with(InsectSprays, reorder(spray, -count, median))
  12. boxplot(count ~ bymedian, data = InsectSprays,
  13. xlab = "Type of spray", ylab = "Insect count",
  14. main = "InsectSprays data", varwidth = TRUE,
  15. col = "lightgray")
  16.  
  17. > set.seed(42) # fix seed
  18. > DF <- data.frame(type=sample(LETTERS[1:5], 100, replace=TRUE),
  19. + cost=rnorm(100))
  20. >
  21. > boxplot(cost ~ type, data=DF) # not ordered by median
  22. >
  23. > # compute index of ordered 'cost factor' and reassign
  24. > oind <- order(as.numeric(by(DF$cost, DF$type, median)))
  25. > DF$type <- ordered(DF$type, levels=levels(DF$type)[oind])
  26. >
  27. > boxplot(cost ~ type, data=DF) # now it is ordered by median
  28.  
  29. bymedian <- with(InsectSprays, reorder(spray, -count, median, **na.rm = TRUE**)
  30. boxplot(count ~ bymedian, data = InsectSprays,
  31. xlab = "Type of spray", ylab = "Insect count",
  32. main = "InsectSprays data", varwidth = TRUE,
  33. col = "lightgray")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement