Guest User

Untitled

a guest
Oct 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #data
  2. df <- data.frame(City = c("NY", "AMS", "BER", "PAR", "NY", "AMS", "AMS", "PAE"),
  3. Time_Diff = c(4, 2, 7, 9, 2, 1, 10, 9),
  4. Outliers = c(0, 0, 0, 0, 0, 1, 1, 0))
  5.  
  6. #data summary
  7. summary <- df %>%
  8. group_by(City) %>%
  9. summarise(Median = median(Time_Diff),
  10. IQR = IQR(Time_Diff),
  11. Outliers = sum(Outliers)) %>%
  12. arrange(desc(Median), desc(IQR), desc(Outliers))
  13.  
  14. summary <- as.data.frame(summary)
  15.  
  16.  
  17. # Create ggplot object
  18. bp <-ggplot(data = df, aes(x = reorder(City, Time_Diff, FUN = median), y= Time_Diff)) # Creates boxplots
  19.  
  20. # Create boxplot figure
  21. bp +
  22. geom_boxplot(outlier.shape = NA) + #exclude outliers to increase visibility of graph
  23. coord_flip(ylim = c(0, 25)) +
  24. geom_hline(yintercept = 4) +
  25. ggtitle("Time Difference") +
  26. ylab("Time Difference") +
  27. xlab("City") +
  28. theme_light() +
  29. theme(panel.grid.minor = element_blank(),
  30. panel.border = element_blank(), #remove all border lines
  31. axis.line.x = element_line(size = 0.5, linetype = "solid", colour = "black"), #add x-axis border line
  32. axis.line.y = element_line(size = 0.5, linetype = "solid", colour = "black")) #add y-axis border line
Add Comment
Please, Sign In to add comment