Guest User

Untitled

a guest
Jun 22nd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. library(tidyverse)
  2. library(plotly)
  3. library(datasets)
  4. data(airquality)
  5.  
  6. # add months
  7. airquality$Month <- factor(airquality$Month,
  8. labels = c("May", "Jun", "Jul", "Aug", "Sep"))
  9.  
  10. # add sample names
  11. airquality$Sample <- paste0('Sample_',seq(1:nrow(airquality)))
  12.  
  13. # boxplot
  14. p <- ggplot(airquality, aes(x = Month, y = Ozone)) +
  15. geom_boxplot()
  16. p <- plotly_build(p)
  17. p
  18.  
  19. library(plotly)
  20.  
  21. vals <- boxplot(airquality$Ozone,plot = FALSE)
  22. y <- airquality[airquality$Ozone > vals$stats[5,1] | airquality$Ozone < vals$stats[1,1],]
  23.  
  24. plot_ly(airquality,y = ~Ozone,x = ~Month,type = "box") %>%
  25. add_markers(data = y, text = y$Day)
Add Comment
Please, Sign In to add comment